[Tutor] Passing functions as arguments to other functions

Steven D'Aprano steve at pearwood.info
Fri Sep 30 08:26:16 EDT 2016


On Fri, Sep 30, 2016 at 09:43:47AM +0100, Alan Gauld via Tutor wrote:
> On 30/09/16 03:43, boB Stepp wrote:
> 
> > 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*. 
> 
> No.
> The function name is just a name like any other name in Python

Alan's correct here -- functions aren't treated specially.

But in the same way that is you say:

x = 999
x

the bare `x` on its own returns the int object 999, so:

def func(): ...

func

the bare `func` on its own returns the function object called "func".

So in *that sense alone*, func without the parentheses is the function 
object.

[...]
> So in your example f is not the function object it is a
> reference to a function object.

You say tomahto, I say edible wolf peach:

http://recipes.howstuffworks.com/fresh-ideas/dinner-food-facts/tomato-called-a-love-apple.htm




-- 
Steve


More information about the Tutor mailing list