Let me explain what your code does
>>> def func1(a):
... def func2(b):
... c = a + b
... print c
... return func2
...
This will create one function func1
which return you another function func2
. func2
is local for func1
>>> func3 = func1(3)
This will create variable func3
and value of func3
is func2
. So when you print value of func3
it will return function.
>>> func3
<function func2 at 0x7fd29fcb66e0>
If you try to access func3.a
then it will not return you 1
because a
is not a attribute of func2
.
>>> func3.a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'a'
a
is local variable, so you cant access it. When you call func3
, it will call func2
with a
as 1
.
>>> func3(1)
4
So this will call func2(1)
where a
is 3
in local func2
.