pass Statement in Python

Spread the love
Contents:
  • pass Statement
  • Example
pass Statement

In Python programming, somewhere a statement is required to write syntactically but we do not want any operation because of that statement. In that case, a pass statement comes in the picture. It is used as a placeholder where syntactically some code is required. When pass statement executes, no operation is carried out. This is particularly useful in situations where code structure is being defined but the implementation is deferred. 

Example
  • Define Empty Class or Function: 

def democlass:       #Empty Class 
               pass
—————————————————–

          def my_fun( ):       #Empty Function
                        pass

  • Use of pass in Conditional Statements
    x=20
    if x<10:
          pass       # Do Nothing
    else:
          print(“Greater”)

  • Use of pass in Loop
    for i in range(10):
             if i%2==0: 
                    pass
            else:
                    print(i, end=’ ‘)

🙂 Happy Learning !

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top