[Tutor] Passing functions as arguments to other functions

Ben Finney ben+python at benfinney.id.au
Fri Sep 30 01:28:00 EDT 2016


boB Stepp <robertvstepp at gmail.com> writes:

> So the impression I am getting is that a function name by itself (with
> no parentheses) is the function *object*.

Yes. The expression ‘func’ resolves to whatever object is referenced by
that name; if it's a function object, you get that object.

The expression ‘func(foo, bar)’ resolves to whatever object is returned
from *calling* the object ‘func’, with the arguments ‘foo, bar’.

> But why does Python require separating the function object from its
> parameters when it is being passed as an argument to another function?

You've already answered your question. An expression resolves to exactly
one object. Either you want the function object, or you want something
else.

In the case of ‘func(foo, bar)’ you will get exactly one object from
that expression. You won't get the ‘func’ object as well; you need a
different expression (the expression ‘func’) to get that.

If you want to talk about different objects at the same time, you need
multiple parameters in which to place those objects.

-- 
 \      “By instructing students how to learn, unlearn, and relearn, a |
  `\         powerful new dimension can be added to education.” —Alvin |
_o__)                                    Toffler, _Future Shock_, 1970 |
Ben Finney



More information about the Tutor mailing list