Python pass Statement (With Examples)

Python pass statement: Here, we are going to learn about pass statement in python, how to use pass statement in Python? By IncludeHelp Last updated : December 18, 2023

Python pass Statement

In Python, the 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 the Python pass statement

Below is the syntax of the pass statement:

pass

Python pass Statement: Examples

To understand the use of the pass statement, practice these examples.

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

Python Tutorial

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.