Python Forum
Why is this the output I am getting? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Why is this the output I am getting? (/thread-11353.html)



Why is this the output I am getting? - wlsa - Jul-04-2018

def func_a():
    print('inside func_a')
def func_c(z):
    print('inside func_c')
    return z()
print(func_c(func_a))
the output I get is
inside func_c
inside func_a
None

I'm having a hard time understanding how putting a function as an input into another function gives me this output.


RE: Why is this the output I am getting? - ichabod801 - Jul-04-2018

You pass func_a to func_c without calling it. func_c prints, and then calls the function that was passed to it (z()). So that calls func_a, which prints. func_a returns None (the default return value) to func_c, which does nothing. func_c returns None to the print function on line 6, and it gets printed.