Python pass Statement
In this page:
What is the pass Statement?
pass is a statement that does literally nothing when executed — it exists purely to satisfy Python's syntax requirement that a block can't be left completely empty, without actually performing any action.
Example: What is the pass Statement?
if True:
pass
print("Done")
pass in Conditional Statements
Inside an if block, pass lets you stub out a branch you haven't implemented yet — if special_case: pass — so the code stays syntactically valid while you plan out what that branch should eventually do.
Example: pass in Conditional Statements
special_case = False
if special_case:
pass
else:
print("Handling normal case")
pass in Loops
A loop body that isn't ready yet still needs *something* inside it to be valid Python; pass fills that gap temporarily so you can write the loop's header now and fill in real logic later without a syntax error in between.
Example: pass in Loops
for i in range(3):
pass
print("Loop finished")
pass in Class Definitions
Writing class CustomError(Exception): pass is a common real-world use — it defines a fully functional, distinctly-named exception type without needing any additional behavior beyond what Exception already provides.
Example: pass in Class Definitions
class CustomError(Exception):
pass
try:
raise CustomError("Something went wrong")
except CustomError as e:
print(e)
pass vs Comments
A comment alone can't satisfy Python's syntax where a statement is required — the interpreter skips comments entirely, so a block containing only a # note still raises an IndentationError; pass is an actual (if inert) statement that fills that requirement.
Example: pass vs Comments
def todo():
pass # a comment alone here would raise IndentationError
todo()
print("todo() ran without error")
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: