[Tutor] Passing Arguments

Alan G alan.gauld at freenet.co.uk
Sat Jul 9 13:19:24 CEST 2005

> # Here I just created a couple of variables to print, and then
> prt_Name returns g.
>def prt_Name():
>    g = 'foo'
>    print g
>    return g
> def get_Name(b):
>    print 'f'
>    print b
> get_Name(prt_Name)

So you are passing a function object into your get_Name function.
Is that what you want? Or do you want to pass the value returned
by the function? Either is valid but its hard to know where your
misunderstanding is until I know your intent...

I'll first assume you actually wanted to pass the return value

You should have called it like:

get_NAme(prtName())  # notice the parens to invoke the prtName

If you did mean to pass the function then your call is OK but
you need to call prtName inside getName, like so:

def get_Name(b):
    print 'f'
    print b()   # notice the parens to invoke b (which is the prtName 

Which solution were you trying to achieve?

Alan G. 

More information about the Tutor mailing list