Write Python. Understand every error.

Open the editor

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.

Try this code in Py-CRAFT

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

Learn the ideas behind it

Other common errors

Share this page: