Re: question about what lamda does
- From: "Dan Bishop" <danb_83@xxxxxxxxx>
- Date: 17 Jul 2006 20:04:05 -0700
nephish@xxxxxxx 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.
.
- References:
- question about what lamda does
- From: nephish
- question about what lamda does
- Prev by Date: Re: range() is not the best way to check range?
- Next by Date: Re: range() is not the best way to check range?
- Previous by thread: question about what lamda does
- Next by thread: Python 2.5b2 Windows binaries
- Index(es):
Relevant Pages
|