conditionals in lambdas?

Fredrik Lundh fredrik at
Fri Nov 3 20:51:06 CET 2000

Michael P. Soulier wrote
>     Hey people. If I want to put conditions in a lambda function, how would I
> go about that?
> def test(string):
>     if string[:3] == 'yes:
>         return 1
>     else:
>         return 0
>     I'd like to make something like this a lambda function. Is that possible?

nope.  lambdas can only contain simple expressions.

also see:
    6.9. Why can't lambda forms contain statements?

    "...the only advantage of using a lambda form instead of
    a locally-defined function is that you don't need to invent
    a name for the function..."


More information about the Python-list mailing list