×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python pass Statement

By IncludeHelp Last updated : December 08, 2024

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 pass statement

Below is the syntax of the pass statement:

pass

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

Comments and Discussions!

Load comments ↻





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