Built-in Exception Types in Python
Python ships with dozens of built-in exception types, each representing a specific, common category of problem. Recognizing the common ones on sight — what they mean and when they typically occur — makes both writing correct except clauses and reading a traceback much faster.
Exception is the common ancestor to catch
Nearly every built-in exception a program should actually handle descends from it.
ValueError: right type, wrong value
Like int("abc") — a string, correctly, but not one that can be parsed as a number.
TypeError: the wrong type entirely
Like "2" + 2 — an operation applied to incompatible types.
KeyError and IndexError: missing lookups
A missing dictionary key, or an out-of-range sequence position, respectively.
A few more come up constantly
FileNotFoundError, ZeroDivisionError, and AttributeError round out the most frequently seen exceptions in everyday code.
try: int("abc")except ValueError as e: print("ValueError:", e) try: "2" + 2except TypeError as e: print("TypeError:", e) try: {"a": 1}["b"]except KeyError as e: print("KeyError:", e)Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Python yourself — building beats watching.