Accessing list values

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.135.36