Python list negative index

"""
Negative index means count backwards.
Counting backwards begins with "-1", while counting forwards begins with "0"
"""

a = [1, 2, 3]
print(a[-1])  # 3
print(a[-2])  # 2
print(a[0])  # 1

你可能感兴趣的:(Python list negative index)