Q:

Python program to define an empty function using pass statement

belongs to collection: Python basic programs

0

An empty function is a function that does not contain any statement within its body. If you try to write a function definition without any statement in python – it will return an error ("IndentationError: expected an indented block").

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider 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 output – there is no statement in the definition part of the function myfunc(), so python compiler considers the next statement (which is a “print” statement in this program) as a statement of the function definition. Thus, an error "IndentationError: expected an indented block" occurs.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python basic programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python program for Zip, Zap and Zoom game... >>
<< Python program for pass statement...