📖 Study: Reading Error Messages
Learn how to decode Python's error messages (tracebacks) to find and fix problems quickly.
Common Python Error Messages
SyntaxError
SyntaxError: invalid syntax
Meaning: Python doesn't understand your code - you've broken a grammar rule.
Common causes:
- Missing colon after if, for, while, def
- Unclosed brackets, parentheses, or quotes
- Using = instead of == in comparisons
- Misspelled keywords
IndentationError
IndentationError: expected an indented block
Meaning: Python expects indented code but didn't find any.
Common causes:
- Code after if/for/while/def not indented
- Mixing tabs and spaces (use 4 spaces consistently)
- Inconsistent indentation levels
NameError
NameError: name 'varible' is not defined
Meaning: Python doesn't recognise a name you're using.
Common causes:
- Typo in variable name (varible vs variable)
- Using a variable before creating it
- Forgetting to put strings in quotes
TypeError
TypeError: can only concatenate str (not "int") to str
Meaning: You're trying to do something with incompatible data types.
Common causes:
- Trying to add a string and number: "Age: " + 15
- Using wrong function on wrong type
- Forgetting to convert user input: int(input(...))
ValueError
ValueError: invalid literal for int() with base 10: 'hello'
Meaning: The value is the wrong format for what you're trying to do.
Common causes:
- Trying to convert non-numeric text to int: int("hello")
- User enters invalid input
IndexError
IndexError: list index out of range
Meaning: You're trying to access a position that doesn't exist.
Common causes:
- Index too large: my_list[10] when list only has 5 items
- Off-by-one: list has indices 0-4, but you use 5
- Accessing empty list