Python Forum
Why is this the output I am getting?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is this the output I am getting?
#1
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.
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020