IndentationError
IndentationError: expected an indented block
Traceback
Traceback (most recent call last):
File "main.py", line 3, in <module>
print("done")
IndentationError: expected an indented blockWhat causes this error
A compound statement (if, for, def, class, etc.) was followed by a line that is not indented. Python requires at least one indented statement in every block body.
How to fix it
Add the intended code body with proper indentation. Use `pass` or `...` as placeholders for empty bodies. Ensure the line after the colon is indented by 4 spaces.
Code that causes this error
def process_data():
print("done")Fixed code
def process_data():
pass # placeholder
print("done")About IndentationError
This error occurs when Python expects an indented block after a compound statement (if, for, while, def, class, etc.) but finds an unindented line or an empty body instead. Every compound statement requires at least one indented line in its body. If you are not ready to implement the body, use the `pass` statement as a placeholder.
This error often appears when writing stub functions or classes, when commenting out the entire body of a block, or when forgetting to indent the body after a colon. The `...` (Ellipsis) literal can also serve as a placeholder in function bodies, particularly in type stubs and abstract methods.
Common scenarios
Writing code with missing colons, parentheses, or brackets
Mixing Python 2 and Python 3 syntax when upgrading a codebase
Copy-pasting code from the web with formatting issues or invisible characters
Using reserved keywords as variable or function names