Hi,

i'm confused by a piece of code with parenthese as this:

----------------code 1------------------------------
>>> def outer():
...   def inner():
...     print 'inside inner'
...   return inner
...
>>> foo = outer()
>>> foo
<function inner at 0x9546668>
>>> foo()
inside inner



----------------code 2-------------------------------
>>> def outer():
...   def inner():
...     print 'inside inner'
...   return inner()
...
>>> foo = outer()
inside inner
>>> foo
>>> foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable


the difference between these two piece of code is that the code 2 has a "()" 
when "return inner".

My questions are:
(1) what is the function difference between these two pieces of code? what does 
"return inner()" and "return inner" mean?
(2) when foo = outer() is run, why output is defferent for two pieces of code?

thanks
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to