📜  list -1 python 代码示例

📅  最后修改于: 2022-03-11 14:47:12.949000             🧑  作者: Mango

代码示例1
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]