It is used when you do not know how many contents of the list are variable until you hit it.
list = ["a", "b", "c", "d", "e"]
print list
['a', 'b', 'c', 'd', 'e']
print list[0]
a
print list[2]
c
print list[5]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
print list[-1]
e
print list[-2]
d
If you know it, there is nothing you can do, but if you don't know it, it will be a powerful skill.
Recommended Posts