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
- Add an indented statement inside the block — even pass works as a placeholder: def my_func(): pass
- Use pass as a stub body while developing: if condition:\n pass
- Check indentation — the body must be indented one level deeper than the header
- 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 3A 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.
