×

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

Last Updated : April 22, 2025

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.

Using pass Statement

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!

Using pass Statement to Define an Empty Function

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!!!

Using pass Statement to Skip Execution

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 Pass Statement Exercise

Select the correct option to complete each statement about the pass statement in Python.

  1. The pass statement is used to ___ a block of code where a statement is syntactically required but no action is needed.
  2. The pass statement is commonly used in ___ blocks, like when defining an empty function or class.
  3. The pass statement does not ___ the flow of execution in the program.

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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