question about what lamda does

nephish at xit.net nephish at xit.net
Tue Jul 18 07:34:33 EDT 2006


ok, i think i get it.
pretty cool.
thanks
-sk


Dan Bishop wrote:
> nephish at xit.net wrote:
> > Hey there,
> > i have been learning python for the past few months, but i can seem to
> > get what exactly a lamda is for.
>
> It defines a function.
>
> f = lambda x, y: expression
>
> is equivalent to
>
> def f(x, y):
>    return expression
>
> Note that lambda is an expression while def is a statement.
>
> > What would i use a lamda for that i
> > could not or would not use a def for ? Is there a notable difference ?
> > I only ask because i see it in code samples on the internet and in
> > books.
>
> Lambdas are typically used as parameters to functions that take
> functions as arguments, like property() and reduce().  You never *need*
> to use one, but sometimes it's convenient.




More information about the Python-list mailing list