Skip to content
Related Articles

Related Articles

Improve Article

Python pass Statement

  • Difficulty Level : Basic
  • Last Updated : 17 Jun, 2020

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


def geekFunction:

Example 2: pass statement can also be used in empty class


class geekClass:

Example 3: pass statement can be used in for loop when user doesn’t know what to code inside the loop


n = 10
for i in range(n):
  # pass can be used as placeholder
  # when code is to added later

Example 4: pass statement can be used with conditional statements 


a = 10
b = 20

Example 5: lets take another example in which the pass statement get executed when the condition is true 


li =['a', 'b', 'c', 'd']
for i in li:
    if(i =='a'):



 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :