Falcolas a écrit :
> Please help me understand the mechanics of the following behavior.
>
>
def d():
>
> header = 'I am in front of '
> def e(something):
> print header + something
> return e
>
>
f = d()
f('this')
>
> I am in front of this
>
de
[snip]
> The "thing" you observe here is a called a closure. It consists of the
> local variables surrounding e. So as long as you keep a reference to e,
> you keep one to the variables of d itself.
>
> Diez
More specifically though it keeps references to the requested variables
only:
def clo
Falcolas schrieb:
> Please help me understand the mechanics of the following behavior.
>
def d():
> header = 'I am in front of '
> def e(something):
> print header + something
> return e
>
f = d()
f('this')
> I am in front of this
del(d)
f(
Please help me understand the mechanics of the following behavior.
>>> def d():
header = 'I am in front of '
def e(something):
print header + something
return e
>>> f = d()
>>> f('this')
I am in front of this
>>> del(d)
>>> f('this')
I am in front of this