Error guide · IndentationError
IndentationError: unexpected indent
A line is indented when nothing above it opened a block.
Example
print("start") print("indented")
What Python says
IndentationError: unexpected indent
As printed by Python 3.12. Other versions may word it slightly differently.
Why it happens
Indentation in Python has meaning: it shows which lines belong inside an if, a loop or a function. A line that is indented for no reason is an error. It often comes from an accidental space at the start of a line, or from pasted code.
How to fix it
print("start") print("indented")
Output: start ⏎ indented
Tips
- Remove the extra spaces so the line lines up with the one above.
- Indent only after a line that ends with a colon.
- Use 4 spaces for each level and never mix tabs and spaces.