if in expression

Hrvoje Niksic hniksic at xemacs.org
Mon Aug 18 10:25:48 CEST 2008


"Diez B. Roggisch" <deets at nospam.web.de> writes:

> Since python 2.5, it is
>
> <then_value> if <cond> else <else_value>
>
> If you want lazy evaluation, you can use lambdas:
>
> iif(cond, lambda: then, lambda: else_)()

Your code uses "iif" and attempts to evaluate a tuple; could you post
an example that works?

I ask because it's not clear what you mean by lazy evaluation in this
context.  The ternary "if" expression introduced in Python 2.5 only
evaluates then_value or else_value depending on the outcome of cond.
How is that different than using a lambda?



More information about the Python-list mailing list