VOOZH about

URL: https://www.geeksforgeeks.org/python/python-pass-statement/

⇱ Python pass Statement - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python pass Statement

Last Updated : 27 Mar, 2026

The pass statement in Python is a placeholder that does nothing when executed.

  • It is used to keep code blocks valid where a statement is required but no logic is needed yet.
  • Examples situations where pass is used are empty functions, classes, loops or conditional blocks.

In Functions

The pass keyword in a function is used when we define a function but don't want to implement its logic immediately. It allows the function to be syntactically valid, even though it doesn't perform any actions yet.

Explanation: fun() is defined but contains pass statement, so it does nothing when called and program continues execution without any errors.

In Conditional Statements

In conditional statements, when no action is needed but a block is still required, pass statement acts as a placeholder to keep the code syntactically valid.

Explanation:

  • When x > 5, the pass statement runs, so nothing happens.
  • If x <= 5, else block executes and prints the message.

In Loops

In loops, pass can be used to skip writing any action during a specific iteration while still keeping the loop structure correct.


Output
0
1
2
4

Explanation:

  • For i == 3, the pass statement ensures nothing happens.
  • For other values, the loop prints the number.

In Classes

The pass statement allows defining empty classes or methods that act as placeholders until actual functionality is added later.

Explanation:

  • EmptyClass is valid even without methods or attributes because of pass.
  • greet() method exists but does nothing yet, letting us build the structure first.
Comment
Article Tags: