The pass statement is a null statement. But the difference between pass and comment is that comment is ignored by the interpreter whereas pass is not ignroed.
The pass statement is generally used as a placeholder i.e. when the user does not know what code to write. So user simply places pass at that line. Sometimes, pass is used when the user doesn’t want any code to execute. So user simply places pass there as empty code is not allowed in loops, function definitions, class definitions, or in if statements. So using pass statement user avoids this error.
Example 1: Pass statement can be used in empty functions
Example 2: pass statement can also be used in empty class
Example 3: pass statement can be used in for loop when user doesn’t know what to code inside the loop
Example 4: pass statement can be used with conditional statements
Example 5: lets take another example in which the pass statement get executed when the condition is true
b c d
- How to write an empty function in Python - pass statement?
- Pass by reference vs value in Python
- How to pass argument to an Exception in Python?
- break, continue and pass in Python
- Difference between continue and pass statements in Python
- Python - pass multiple arguments to map function
- Python | Split and Pass list as separate parameter
- Pass list as command line argument in Python
- Loops and Control Statements (continue, break and pass) in Python
- with statement in Python
- Python return statement
- Nested-if statement in Python
- Python Continue Statement
- Python break statement
- Statement, Indentation and Comment in Python
- Using else conditional statement with for loop in python
- Check multiple conditions in if statement - Python
- How to pass multiple arguments to function ?
- Python - Read blob object in python using wand library
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.