What is "lambda x=x : ... " ?

zslevi@gmail.com levilista at gmail.com
Thu Jan 10 13:36:48 EST 2008


I've figured it out, it is default argument.
print  y()
gives 13 as result.

It's a bit evil though.
I hope this post will be useful some newbie like i'm now someday :)

On Jan 10, 7:25 pm, "zsl... at gmail.com" <levili... at gmail.com> wrote:
> I'm reading this page:http://www.ps.uni-sb.de/~duchier/python/continuations.html
> and I've found a strange usage of lambda:
>
> ####################
> Now, CPS would transform the baz function above into:
>
> def baz(x,y,c):
>         mul(2,x,lambda v,y=y,c=c: add(v,y,c))
>
> ###################
>
> What does "y=y" and "c=c" mean in the lambda function?
> I thought it bounds the outer variables, so I experimented a little
> bit:
>
> #################
> x = 3
> y = lambda x=x : x+10
>
> print y(2)
> ##################
>
> It prints 12, so it doesn't bind the variable in the outer scope.




More information about the Python-list mailing list