15 Python errors, what they mean and how to fix them
The errors you meet most, explained as meaning, common causes and a fix. Each example was reproduced with the runner on this page.
- NameErrorPython met a name it does not know.
- SyntaxErrorA line is shaped in a way Python does not allow.
- IndentationErrorThe indentation does not fit.
- TypeErrorThis kind of value cannot do that.
- ValueErrorThe type is right, but the value is not.
- IndexErrorYou asked a list for a position it does not have.
- KeyErrorYou asked a dictionary for a key it does not have.
- ZeroDivisionErrorYou divided by zero.
- AttributeErrorYou called a feature that this value does not have.
- ModuleNotFoundErrorPython could not find the module you tried to import.
- ImportErrorThe module was found, but the name you imported is not in it.
- RecursionErrorA function called itself too many times.
- FileNotFoundErrorThe file you tried to open does not exist.
- UnboundLocalErrorYou read a variable inside a function before it had a value.
- TabErrorTabs and spaces are mixed in the indentation.