Pass Statement
In Python, the pass keyword is used to execute nothing; it means, when we don't want to execute code, the pass can be used to execute empty. It is the same as the name refers to. It just makes the control to pass by without executing any code. If we want to bypass any code pass statement can be used.
Suppose we have a loop, and we do not want to execute right this moment, but we will execute in the future. Here we can use the pass.
If statements can not be empty but if you want to have an if statement with no content, put in the pass statement to avoid getting an error.
Example 1 :
a=33
b=200
if(b>a): # having an empty if statement like this, would raise an error without the pass statement
pass
Example 2:
- # pass is just a placeholder for
- # we will add functionality later.
- values = {'P', 'y', 't', 'h','o','n'}
- for val in values:
- pass
No comments:
Post a Comment