[Tutor] Passing functions as arguments to other functions
boB Stepp
robertvstepp at gmail.com
Thu Sep 29 22:43:57 EDT 2016
I believe I understand the barebone mechanics on how to do this. But
I do not understand the rationale of why Python does it the way it
does. Say
def f(g, *args):
g(*args)
def g(*args):
# Do something.
do_things = f(g, *args)
is the outline of how I understand the mechanics of doing this. But
noob boB initially want to do instead:
def f(g(*args)):
g(*args)
def g(*args):
# Do somenthing.
do_things = f(g(*args))
which, of course, will give me a syntax error.
Also, I note that if I just type a function name without the
parentheses in the interpreter, I will get something like this:
>>> def f():
pass
>>> f
<function f at 0x000001F775A97B70>
So the impression I am getting is that a function name by itself (with
no parentheses) is the function *object*. But why does Python require
separating the function object from its parameters when it is being
passed as an argument to another function?
--
boB
More information about the Tutor
mailing list