Chapters
Python114 chapters

ReferenceException types

IndexError

A sequence position past the end.

Signature

IndexError(message)

Returns

Raised by indexing, never by slicing.

Example

Python
names = ["Ada"]
try:
    names[5]
except IndexError as problem:
    print("IndexError:", problem)

print(names[0:99])

Output

IndexError: list index out of range
['Ada']

See also