Skip to main content

The pass Statement

Python does not accept an empty if statement. If yours has no content for some reason, write pass in it to avoid an error.

Running pass does nothing at all. It is a null operation whose only job is to hold a place.

Example

Prompt
Write a Python program that uses the pass statement inside an if block. Set a = 33 and b = 200, then check if b > a and use pass as placeholder.
Output: complete Python program

Why Use pass?

Here are some situations where pass comes in handy:

  • You are sketching code structure before writing the logic
  • The syntax demands a statement, but no action is needed
  • You want a placeholder for future code during development
  • A function or class stays empty until you implement it later

pass in Development

You may want to lay out a program's shape first and fill in the details later. With pass in the empty spots, that draft stays free of syntax errors.

Example

Holding a place for code to come:

Prompt
Write a Python program that uses pass as a placeholder during development. Set age to 16 and use pass in the if block for underage logic, with an else that prints "Access granted".
Output: complete Python program

pass vs Comments

Python skips comments completely, whereas pass is a real statement that does get executed, even though it has no effect. So wherever Python expects a statement, a comment alone won't do and you need pass.

Example

With pass, this code runs fine:

Prompt
Write a Python program demonstrating that pass works where a comment alone would cause an error. Use pass in an if block for score > 90, then print "Score processed".
Output: complete Python program

Example

With only comments, the block is empty and you get an error:

main.py
score = 85

if score > 90:
  # This is excellent
  # This will raise an IndentationError

pass with Multiple Conditions

Every branch of an if-elif-else statement can use pass, not just the first.

Example

Using pass in an elif branch:

Prompt
Write a Python program using pass in an elif branch of an if-elif-else statement. Check if value is negative, zero (use pass), or positive.
Output: complete Python program

pass in Other Contexts

This page looks at pass in if statements, but it is also common in loops, functions and classes.

Example

pass as the body of a function:

Prompt
Write a Python program that defines a function with pass as a placeholder. Create calculate_discount(price) that does nothing yet.
Output: complete Python program