python list中的最后一个元素
# To get the last element in a list you use -1 as position
bikes = ['trek', 'redline', 'giant']
bikes[-1]
# Output:
# 'giant'
python获取list的最后一个元素
mylist = [0, 1, 2]
mylist[-1] = 3 # sets last element
print(myList[-1]) # prints Last element
如何在python中找到list的最后一个索引
# Use an Index of -1
l = [1,2,3,4]
print(l[-1])
# Returns 4
python list中item的最后一个索引
def list_rindex(li, x):
for i in reversed(range(len(li))):
if li[i] == x:
return i
raise ValueError("{} is not in list".format(x))