Documentation

Type defined in library builtins

IndexError

Python raises an index error when indexing into a list — my_list[index] — and the index is out of range.

Note that the text of the error message depends on the implementation. Different versions of Python and different checking tools will give slightly different messages.

Code
sizes = ["S", "M", "L"] chosen = sizes[3]
error
IndexError: list index out of range
Code
sizes = ["S", "M", "L"] sizes[3] = "XL"
error
IndexError: list index out of range
Code
sizes = ["S", "M", "L"] chosen = sizes[-4]
error
IndexError: list index out of range

Logo of PyTamaro

PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI

Privacy PolicyPlatform Version a9143b0 (Sun, 14 Dec 2025 12:09:46 GMT)