Python program to define an empty function using pass statement

Python void capacity utilizing pass articulation: Here, we will figure out how to characterize an unfilled capacity by utilizing pass explanation in Python?

A vacant capacity is a capacity that doesn’t contain any announcement inside its body. In the event that you attempt to compose a capacity definition with no announcement in python – it will restore a blunder (“IndentationError: anticipated an indented square”).

Think about the given code,

# python code to demonstrate example of 
# pass statement

# an empty function definition without any statement
def myfunc():
    
# main code 
print("calling function...")
myfunc()
print("End of the program")

Output:

  File "/home/main.py", line 8
    print("calling function...")
        ^
IndentationError: expected an indented block

See the yield – there is no announcement in the definition part of the capacity myfunc(), so python compiler thinks about the following articulation (which is a “print” explanation in this program) as an announcement of the capacity definition. In this manner, a blunder “IndentationError: anticipated an indented square” happens.

Characterizing an unfilled capacity with “pass” articulation

On the off chance that there is no announcement in the capacity, for example, we need to make it as a vacant capacity – we can utilize pass proclamation. As we have talked about in the previous post (pass articulation in python) that, a pass explanation is an invalid proclamation and it sits idle.

Python code for an unfilled capacity with pass explanation:

# python code to demonstrate example of 
# pass statement

# an empty function definition with pass statement
def myfunc():
    pass

# another function having statement
def urfunc():
    print("This is your function")
    
# main code 
print("calling function...")

# calling functions
myfunc()
urfunc()

print("End of the program")

Output:

calling function...
This is your function
End of the program

See the yield – there is no blunder in the program, it assembled effectively. We just composed a pass proclamation with the vacant capacity myfunc().

Leave a Comment

error: Alert: Content is protected!!