Nearby lessons

51 of 159

Python - Pass Statement

📌 What You Will Learn
  • Define the pass statement and what it does
  • Explain why pass is required when Python does not allow empty blocks
  • Use pass as a placeholder inside if blocks, loops and functions
  • Compare pass with break
  • Compare pass with continue

pass Statement

The pass statement does nothing.

It is used as a placeholder where Python expects a statement.

Why pass is Required?

Sometimes we plan to write code later.

Since Python does not allow an empty block, we use the pass statement.

Example 1 - pass Statement

🐍Code Cell
1if True:
2 pass
3 
4print("Program Completed")
Output
Program Completed

Example 2 - pass inside Loop

🐍Code Cell
1for i in range(5):
2 pass
3 
4print("Loop Completed")
Output
Loop Completed

Example 3 - Empty Function

🐍Code Cell
1def display():
2 pass
3 
4print("Function Created Successfully")
Output
Function Created Successfully

Difference Between break and pass

break pass
Stops the loop. Does nothing.
Changes program execution. Acts as a placeholder.

Difference Between continue and pass

continue pass
Skips the current iteration. Does nothing.
Works only inside loops. Can be used anywhere a statement is required.
📝 Key Takeaways
  • The pass statement does nothing and acts as a placeholder
  • Python does not allow an empty block, so pass is used as a filler
  • pass can be used anywhere a statement is required
  • break stops a loop while pass does nothing
  • continue skips the current iteration while pass does nothing

🧠 Test Your Knowledge

3 Questions
Progress: 0 / 3