ProjectStack
python

IndentationError: expected an indented block

A statement that opens a block (like if, def, for, or class) is followed by a line at the same indentation level instead of an indented body. Python requires at least one indented statement inside every block.

Common causes

  • A function, class, or if block has no body — you started the block but wrote nothing inside it
  • The body was accidentally de-indented to the same level as the block header
  • You used a comment (#) as the only content of a block — comments don't count as statements
  • You wrote the block header but forgot to write the body before moving on

How to fix it

  1. Add an indented statement inside the block — even pass works as a placeholder: def my_func(): pass
  2. Use pass as a stub body while developing: if condition:\n pass
  3. Check indentation — the body must be indented one level deeper than the header
  4. If you meant to skip the body temporarily, use pass (not a comment)

Example

File "app.py", line 4 def greet(): print('hi') ^ IndentationError: expected an indented block after function definition on line 3

A function definition whose body is at the same indentation as the def line

Have a different error?

Paste any error message into the Error Translator to get an instant explanation.