Python errors for beginners: what they mean and how to fix them
The last line of a Python error message names the error type. Find that name below: each page says what it means, shows code that fails, the real error text and the corrected code.
Common errors
- NameError NameError in Python: name is not defined
- SyntaxError SyntaxError in Python: invalid code structure
- IndentationError IndentationError in Python: wrong indentation
- TypeError TypeError in Python: wrong type of value
- ValueError ValueError in Python: unsuitable value
- IndexError IndexError in Python: list index out of range
- KeyError KeyError in Python: no such key in the dictionary
- AttributeError AttributeError in Python: no such method or attribute
- ZeroDivisionError ZeroDivisionError in Python: division by zero
- RecursionError RecursionError in Python: maximum recursion depth exceeded