Because Python uses indentation to define blocks, an empty block, like a function body, if branch, or loop body with nothing in it, is a syntax error — pass exists purely to satisfy that requirement without doing anything at runtime. It's commonly used for functions or classes stubbed out during early development, for branches that intentionally do nothing, or for explicitly catching and silently ignoring specific exceptions.
1Understanding pass Statement
Because Python uses indentation to define blocks, an empty block, like a function body, if branch, or loop body with nothing in it, is a syntax error — pass exists purely to satisfy that requirement without doing anything at runtime. It's commonly used for functions or classes stubbed out during early development, for branches that intentionally do nothing, or for explicitly catching and silently ignoring specific exceptions.
pass is different from a docstring-only function body — a function containing only a string literal is valid without pass, since the string itself counts as a statement, but pass is still the clearest way to say 'deliberately empty' when there's no docstring.
def upcoming_feature():
pass
upcoming_feature()
print("Called without error")2Practical Example
Here is a real-world application of pass Statement showing how it is used in production Python code.
for item in [1, 2, 3]:
if item == 2:
pass # nothing special for this case yet
else:
print(item)3Best Practices
Follow these guidelines when working with pass Statement:
1. Use pass for stub functions/classes during early development instead of leaving a syntax error
2. Prefer pass over a meaningless placeholder statement when you need a genuinely empty block
3. Avoid pass in an except block unless silently ignoring that exception is truly the intended behavior — it's a common way to accidentally hide real bugs
Tip: pass is different from a docstring-only function body — a function containing only a string literal is valid without pass, since the string itself counts as a statement, but pass is still the clearest way to say 'deliberately empty' when there's no docstring.
def upcoming_feature():
pass
upcoming_feature()
print("Called without error")