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
Output: complete Python program
a = 33
b = 200
if b > a:
pass
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:
Output: complete Python program
age = 16
if age < 18:
pass # TODO: Add underage logic later
else:
print("Access granted")
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:
Output: complete Python program
score = 85
if score > 90:
pass # This is excellent
print("Score processed")
Example
With only comments, the block is empty and you get an error:
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:
Output: complete Python program
value = 50
if value < 0:
print("Negative value")
elif value == 0:
pass # Zero case - no action needed
else:
print("Positive value")
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:
Output: complete Python program
def calculate_discount(price):
pass # TODO: Implement discount logic
# Function exists but doesn't do anything yet