if in expression
Hrvoje Niksic
hniksic at xemacs.org
Mon Aug 18 07:48:13 EDT 2008
Fredrik Lundh <fredrik at pythonware.com> writes:
> Hrvoje Niksic wrote:
>
>>> 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?
>
> the second part of Diez' answer is a reply to the second part of the
> OP's question.
Ah, that explains it. Sorry about the noise!
More information about the Python-list
mailing list