Errors and Exceptions
Every programmer sees errors daily. Learn to read them calmly, fix the common ones and handle the expected ones.
- 1Python Exceptions: try, except, else and finallyAn exception is Python's signal that something went wrong while the program was running. If nothing handles i…✓
- 2Python TypeError: What It Means and How to Fix ItA TypeError means Python was asked to do something with a value whose type doesn't support it, such as adding…Error explained✓
- 3Python KeyError: What It Means and How to Fix ItA KeyError is raised when you use square brackets to ask a dictionary for a key it does not contain, like use…Error explained✓
- 4Python IndexError: list index out of rangeAn IndexError happens when you ask a list, tuple or string for a position that doesn't exist, such as item 3 …Error explained✓
- 5Python NameErrorA NameError means Python looked for a name (a variable, function or module) in every scope it checks and foun…Error explained✓
- 6Python SyntaxErrorA SyntaxError means Python could not parse your code because it breaks the language's grammar, so the whole f…Error explained✓
- 7Python IndentationErrorAn IndentationError means the spaces at the start of a line don't match the block structure Python expected, …Error explained✓
- 8Python ValueErrorA ValueError means a function received a value of the correct type but with content it cannot accept, such as…Error explained✓
- 9Python AttributeErrorAn AttributeError means you used a dot to reach a variable or method that the object does not have, usually b…Error explained✓
- 10Python ModuleNotFoundError: No module namedA ModuleNotFoundError means an import statement named a module that Python could not find in the standard lib…Error explained✓
- 11Python ZeroDivisionError: Division by ZeroA ZeroDivisionError means a division, floor division, modulo or power operation had zero as the divisor, whic…Error explained✓
- 12Python FileNotFoundError: No such file or directoryA FileNotFoundError means Python tried to open or access a file or folder path that does not exist, usually b…Error explained✓
- 13Python UnboundLocalErrorAn UnboundLocalError means a function used a local variable before it had a value, which happens because assi…Error explained✓
- 14Python RecursionErrorA RecursionError means a function kept calling itself (directly or indirectly) until Python's call-stack dept…Error explained✓
- 15Python AssertionErrorAn AssertionError means an assert statement checked a condition that turned out to be False, so something you…Error explained✓
- 16Python StopIterationStopIteration is the exception an iterator raises from next() when it has no more values to give, which for l…Error explained✓
Start with Python Exceptions: try, except, else and finally →
About Errors and Exceptions
Every programmer sees errors daily, and reading them quickly is a core skill. These lessons explain how to read a traceback, then give one page for each common exception, covering its causes and the fix: TypeError, KeyError, IndexError, NameError, SyntaxError, ValueError and more. Finish with the exceptions lesson on try, except, else, finally and raise to handle failures on purpose.
Related reference: Glossary: exception · Python how-to guides
Further reading (official documentation)
Practice for this topic
Python Exceptions: try, except, else and finally exercises
4 exercises · checked in your browser
Python TypeError: What It Means and How to Fix It exercises4 exercises · checked in your browser
Python KeyError: What It Means and How to Fix It exercises4 exercises · checked in your browser
Python IndexError: list index out of range exercises4 exercises · checked in your browser
Python NameError exercises4 exercises · checked in your browser
Python SyntaxError exercises4 exercises · checked in your browser
Python IndentationError exercises4 exercises · checked in your browser
Python ValueError exercises4 exercises · checked in your browser
Python AttributeError exercises4 exercises · checked in your browser
Python ModuleNotFoundError: No module named exercises4 exercises · checked in your browser
Python ZeroDivisionError: Division by Zero exercises4 exercises · checked in your browser
Python FileNotFoundError: No such file or directory exercises4 exercises · checked in your browser
Python UnboundLocalError exercises4 exercises · checked in your browser
Python RecursionError exercises4 exercises · checked in your browser
Python AssertionError exercises4 exercises · checked in your browser
Python StopIteration exercises4 exercises · checked in your browser