Home »
Python
Python pass statement
Python pass statement: Here, we are going to learn about pass statement in python, how to use pass statement in python?
Submitted by IncludeHelp, on April 11, 2019
pass statement in Python
In python pass statement is a null statement or we can say it's a dummy statement – which does nothing. It can be used where you do not want to execute any statement (i.e. you want to keep any block empty).
For example – if you have any blank body of any statement like if statement, loop statement, etc, we can use pass there.
Syntax of pass statement:
pass
Example 1: Here, we are writing two pass statement after the print statements
# python example of pass statement
print("Hello")
pass
print("world!")
pass
print("Good bye!")
Output
Hello
world!
Good bye!
Example 2: Here, we are using pass statement to define an empty function
# python example of pass statement
def myfun():
pass
def urfun():
print("this is your function")
# main code
print("Hi")
# calling both of the functions
myfun()
urfun()
print("Bye!!!")
Output
Hi
this is your function
Bye!!!
Example 3: Here, we are taking an integer number, checking it's positive or negative – pass the execution if number is zero
# python example of pass statement
num = 10
if num>0:
print("It's a positive number")
elif num<0:
print("It's a negative number")
else:
pass
print("End of the program")
Output
It's a positive number
End of the program
TOP Interview Coding Problems/Challenges