Python Control Statements
Python Pass
Learn Python Pass with clear explanations, Python examples, and practical programming guidance.
What is the Python pass statement?
pass is a statement that does nothing. It is used as a placeholder when Python requires an indented block, but you do not want to add behavior yet.
Unlike a comment, pass is valid executable Python syntax. The interpreter runs it and immediately moves to the next statement.
Syntax of pass
def function_name():
passThe function is valid even though its body is empty. You can replace pass with real code later.
Use pass in a function
An empty function can be created while you are planning an application:
def send_greeting():
pass
send_greeting()
print("The function ran without an error.")Output
The function call produces no output because its only statement is pass.
Use pass in a conditional statement
Use pass when a condition is intentionally left without behavior:
number = 5
if number > 5:
pass
else:
print("The number is 5 or less.")Output
Use pass in a loop
In this example, the loop keeps running, but it performs no special action when the value is 5:
for number in range(10):
if number == 5:
pass
else:
print(number)Output
1
2
3
4
6
7
8
9
Here, the else block controls what is printed. The pass statement itself does not skip the loop or print anything.
Use pass in an empty class
A class body cannot be empty. Use pass while the class design is still being planned:
class Report:
pass
report = Report()
print(type(report).__name__)Output
Use pass in a method
You can define a method as a placeholder and implement it later:
class Employee:
def calculate_bonus(self):
pass
employee = Employee()
employee.calculate_bonus()
print("Employee object created.")Output
The method call is valid and returns None implicitly because the method has no return statement.
pass versus continue and break
| Statement | What it does | Effect on a loop |
|---|---|---|
pass | Does nothing. | The current iteration continues normally. |
continue | Skips the remaining statements in the current iteration. | Moves to the next iteration. |
break | Stops the nearest loop. | No later iterations run. |
When should you use pass?
- When a function or class is planned but not implemented yet.
- When a condition is intentionally ignored.
- When a required block must remain syntactically valid during development.
- When creating a minimal example or a temporary prototype.
Use comments to explain why a block is empty. Replace pass with real behavior when the feature is implemented.
Further Reading
Continue learning with these related Python tutorials:
Continue learning
