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").
# 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.
Consider the given code,
Output
File "/home/main.py", line 8 print("calling function...") ^ IndentationError: expected an indented blockSee 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