Python exceptions
Every built-in exception, from KeyError to ExceptionGroup: what raises it, the exact message Python prints, and how to handle it. LIVE entries have an in-browser Trigger / Raise / Handle demo.
Something you asked for is not there: a key, an index, an attribute or a variable.
LIVE
AttributeError
AttributeError(*args, name=None, obj=None)
Raised when an attribute reference or assignment fails — obj.x where obj has no x.
LIVEIndexError
IndexError(*args)
Raised when a sequence index (list, tuple, str, range, bytes) is outside the valid range.
LIVEKeyError
KeyError(*args)
Raised when a dict (or other mapping) lookup uses a key that is not there.
LIVENameError
NameError(*args, name=None)
Raised when a bare name is used that is not defined in any enclosing scope.
LIVEUnboundLocalError
UnboundLocalError(*args)
Raised when a function reads a local variable before any value has been assigned to it.