Built-in Exceptions
IndexError — exception class
A sequence index is out of range. Negative indices can be valid, but slicing clips ordinary endpoints instead of raising this exception. Choose an appropriate boundary check or handle IndexError when absence is expected. Catch IndexError when this category is the recovery boundary; do not rely on the exact human-readable message.
Formal Syntax & Structure
python syntaxpython
IndexErrorReturn Value
type
The class object IndexError; this reference documents the class identity, not a universal constructor signature.
Working Example
Example Snippetpython
try: [10][2]except IndexError as error: print(type(error).__name__)