Theoretical question about Lambda
Alex Martelli
aleax at aleax.it
Thu May 2 13:00:11 EDT 2002
Bengt Richter wrote:
...
>>> Is there any forced need for Lambda's in Python ? I mean does Lambda
>>> contribute anything that cannot be done otherwise in Python ?
>>
>>Not really. lambda lets you have an anonymous function, and create
>>a function within an expression (while def is a statement and does
> A thought: being ble to do it in an expression allows taking advantage
> of short-circuit evaluation to avoid some problem in a lambda def form
> vs another.
...while doing it with a def would let you much more easily with
an appropriate if/else:
if doitoneway:
def foo(): return whatever
else:
def foo(): return somethingelse
> What do you think re short circuit evaluation vav lambda?
Given the lack of a ternary operator in Python (insert appropriate
smiley fraction here), if/else is much more comfortable for this.
Alex
More information about the Python-list
mailing list