Pass Statement


 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:

  1. # pass is just a placeholder for  
  2. # we will add functionality later.  
  3. values = {'P''y''t''h','o','n'}  
  4. for val in values:  
  5.     pass  



No comments:

Post a Comment