← Back to Python Course | Chapter 3: Control Flow | Lesson 8 of 10

Python pass Statement

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?

python
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

python
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

python
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

python
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

python
def todo():
    pass  # a comment alone here would raise IndentationError

todo()
print("todo() ran without error")

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.