question about what lamda does

nephish at xit.net nephish at xit.net
Tue Jul 18 10:57:41 EDT 2006


so a lamda needs to stay at one expression, and use more than one lamda
for more expressions ?

i think i get it.

sk

Nick Vatamaniuc wrote:
> Use it anywhere a quick definition of a function is needed that can be
> written as an expression. For example when a callback function is
> needed you could say:
> def callback(x,y):
>   return x*y
> some_function(when_done_call_this=callback)
> But with lambda you could just write
> some_function(when_done_call_this=lambda x,y:x*y)
> Note: because it is an _expression_ you cannot do stuff like 'if..else'
> inside of lambda.
>
> -Nick V.
>
> 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. 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.
> > 
> > thanks for any clarity
> > 
> > sk




More information about the Python-list mailing list