Python errors explained
The 14 errors beginners hit most, in plain English, each with a program to fix.
- SyntaxError: Python could not read your code at all, so nothing ran.
- IndentationError: The spaces at the start of a line do not match what Python expects.
- NameError: You used a name Python has never seen.
- TypeError: You tried to join text and a number with +.
- TypeError: You called a function with the wrong number of arguments.
- ValueError: The type is right but the value inside it is not.
- IndexError: You asked for a position that does not exist in the list.
- KeyError: That key is not in the dictionary.
- AttributeError: You used a method on something that does not have it, very often None.
- ZeroDivisionError: You divided by zero, which has no answer.
- ModuleNotFoundError: Python cannot find the module you tried to import.
- UnboundLocalError: A function changes a variable it can only see from outside.
- RecursionError: A function kept calling itself and never stopped.
- FileNotFoundError: The file you tried to open is not where Python looked.