Error guide · IndentationError
IndentationError: unindent does not match any outer indentation level
A line steps back to a position that no earlier line used.
Example
def check(x): if x > 0: print("positive") print("done")
What Python says
IndentationError: unindent does not match any outer indentation level
As printed by Python 3.12. Other versions may word it slightly differently.
Why it happens
When you leave a block, the next line must line up exactly with an earlier level, such as the if or the def. Here the last line uses 6 spaces, but only 0, 4 and 8 exist above it. Python cannot tell which block it belongs to.
How to fix it
def check(x): if x > 0: print("positive") print("done") check(5)
Output: positive ⏎ done
Tips
- Line it up with the
if(4 spaces) or with theprintabove it (8 spaces). - In Py-CRAFT the Tab key always adds exactly 4 spaces, which avoids this mistake.
- Retype the indentation of the whole block if it looks right but still fails.