Code with the error

is_raining = True
if is_raining:
print("Take an umbrella")

Error message (Python 3.12, last line)

IndentationError: expected an indented block after 'if' statement on line 2

Corrected code

is_raining = True
if is_raining:
    print("Take an umbrella")

Output

Take an umbrella

Common causes

  • “expected an indented block”: nothing is indented after a line ending with a colon.
  • “unexpected indent”: a line has extra spaces for no reason.
  • “unindent does not match any outer indentation level”: the line is shifted back by the wrong number of spaces.
  • Tabs and spaces are mixed in one file.

Practise in the course

Lesson: Conditions

Frequently asked questions

How many spaces should I use?

Four spaces per level is the usual Python style. What matters most is that one block uses the same number.

Is IndentationError a kind of SyntaxError?

Yes. It is a subtype of SyntaxError, so the program does not start until the indentation is fixed.