ShareYourGroupShareYourGroupError Explainer

Python IndentationError: expected an indented block

A plain-words explanation of this Python message: what it means, the usual causes, and the steps that fix it.

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

Make the error yourself

Run with Python 3.14.10. This is the smallest example we could find that shows it.

Python program (main.py)

age = 20
if age >= 18:
print("adult")

Output (the real message)

File "main.py", line 3
    print("adult")
    ^^^^^
IndentationError: expected an indented block after 'if' statement on line 2

Why it happens

In Python the spaces at the start of a line are part of the program: they show which lines belong to an if, for, while, def or class. After a line that ends in a colon, Python expects at least one line that is pushed in. Here the print is at the same level as the if, so the if has no body.

The message names the statement and its line, "after 'if' statement on line 2". Look at that line and the one below it.

How to fix it

  1. Push the lines that belong inside the block in by four spaces.
  2. Keep the same amount for every line of the block.
  3. If you want an empty block for now, write the word pass as its body.
  4. Do not mix tabs and spaces. Set your editor to insert four spaces when you press Tab.

The corrected version

Python program (main.py)

age = 20
if age >= 18:
    print("adult")

Output (the corrected version)

adult

How to avoid it

Turn on "show whitespace" in your editor while you learn. Let the editor indent for you: after you type the colon and press Enter it will usually start the next line pushed in.

Questions

What is the difference between IndentationError and TabError?

TabError means that tabs and spaces were mixed in a way that makes the structure unclear. IndentationError covers a missing or wrong amount of indentation.

This is an independent guide. It is not connected with Python, Microsoft, Google, GitHub or the Git project. Product names belong to their owners. Examples were run on 13 November 2026 in a practice folder or a blank workbook; your version may word a message slightly differently.