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

Python pass Statement

pass is a placeholder that does nothing, like a blank page in a notebook saving a spot for later. Python needs something in a block, so pass fills the gap.
Syntax
python
if condition:
    pass  # placeholder, does nothing

def function_name():
    pass

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  # does nothing, just satisfies Python's syntax
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  # placeholder for logic not implemented yet
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  # placeholder, loop body has no real logic yet
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  # no extra behavior needed beyond what Exception already provides

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")
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Confusing pass with continue; pass does nothing and the loop body keeps running, while continue skips the rest of the iteration.
  2. Leaving an empty block without pass, e.g. if x: followed by nothing, which raises IndentationError.
  3. Leaving pass placeholders in finished code, so the function silently returns None.

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.