Python errors: what IndentationError, NameError and TypeError mean
Reading and fixing the most common errors.
All lessons · Python lessons: learn from scratch
How to read an error message
The last line names the kind of error and the reason; the lines above show the file and line number. Read from the bottom up.
Common errors
- IndentationError — wrong indentation; use 4 spaces and do not mix tabs and spaces.
- SyntaxError — a colon, bracket or quote is missing.
- NameError — the variable is not defined or misspelled (Name ≠ name).
- TypeError — an operation on the wrong type, e.g. text + number.
- IndexError — using a position that is not in the list.
- ModuleNotFoundError — the library is not installed: pip install name.
try:
x = int(input("Number: "))
except ValueError:
print("That was not a number")