function/method assigment

Steve Holden steve at
Fri Apr 13 18:34:15 CEST 2007

viscroad at wrote:
> I have a confusion when I do some practice, the code and output are as
> following,
>>>> def fun():
> 	print 'In fun()....'
>>>> testfun = fun()
> In fun()....
>>>> print testfun
> None
>>>> testfun2 = fun
>>>> print testfun2
> <function fun at 0x00CC1270>
>>>> print testfun2()
> In fun()....
> None
> what is 'testfun'? Why it is 'None'? And print testfun2(), what is the
> meaning of 'None'?
> Thanks!
When a function does not specifically return a value then its return
value is a particular value known as None, the only instance of the None

So testfun is the result of calling the fun function, and it's None
because fun() does not return a value.

Since testfun2 is just another reference to the fun function, testfun2()
is None for exactly the same reasons.

Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd
Skype: holdenweb
Recent Ramblings

More information about the Python-list mailing list