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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.