In this section, you will learn slicing, accessing, adding, deleting, and updating the values in a list.
In order to access list values, use list names with positional index in square brackets. For example, consider the following code snippet:
>>> Avengers = ['hulk', 'iron-man', 'Captain', 'Thor'] >>> Avengers[0] 'hulk' >>> Avengers[3] 'Thor' >>> Avengers[-1] 'Thor' >>> Avengers[4] Traceback (most recent call last): File "<pyshell#5>", line 1, in <module> Avengers[4] IndexError: list index out of range
If the desired index is not found in the list, then the interpreter throws IndexError
.