Pass Statement in Python

Pass Statement in Python

Pass statement in Python used to delay the time of compilation or when we do not know what code to write. In any function of a parent class which is useless to that class , but it is an useful function to it’s child classes  to avoid any error in base class then we just use pass statement.

use of pass statement in python

Pass Statement in Python

In python , Pass statement is a null statement. Interpreter does not ignores pass statement eventually it does not do anything about pass statement.

Implementation :

  • If there is an empty body of function or class we can use pass statement.
def PrepInsta( ) :
    pass
class prepInsta :
    pass
pass statement in python

Code #1: 

  • Pass statement in function and class.
Run
#Pass statement 
#we can use pass statement for an empty funtion or class 
def prepInsta():
    pass 
class prepInsta:
    pass

Code #2:

  • Pass statement in loop and decision making.
Run
#Pass statement 
#we can use pass statement for an condition to skip
 b=10 
for i in range(5,12):
    if(i==b):
        pass 
    else:
        print('Not passed for ', i)
Output:
Not passed for 5
Not passed for 6
Not passed for 7
Not passed for 8
Not passed for 9
Not passed for 11

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription