Answers for "python list[-1]"

0

list -1 python

l = [1,2,5,9,7,4,5]

# what are you referring to?
# 1) l[-1] is the last element of list
print(l[-1])
>>> 5

# 2) l[:-1] returns all the elements of the list but the last one
print(l[:-1])
>>> [1,2,5,9,7,4]
Posted by: Guest on May-18-2021
2

python get element by index

# To return the index of the first occurence of element x in lst
ind = lst.index(x)
Posted by: Guest on March-26-2020

Python Answers by Framework

Browse Popular Code Answers by Language