closures and dynamic binding

Paul Boddie paul at boddie.org.uk
Wed Oct 1 07:04:18 EDT 2008


On 1 Okt, 12:43, jhermann <Juergen.Herm... at 1und1.de> wrote:
>
> f = [lambda n=n: n for n in range(10)]
> print f[0]()
> print f[1]()
>
> Note the "n=n", this prints 0 and 1 instead of 9/9.

Yes, Terry mentioned this in his response to my first message. Not
with lambdas, however, but he did state that he didn't believe that
such a distinction needed to be made clear to everyone.

Paul



More information about the Python-list mailing list