if does not evaluate
Jim Newton
jimka at rdrop.com
Mon Jun 7 16:20:01 EDT 2004
this suggestion does not work because
expr2 evaluates even if expr1 is TRUE.
Tor Iver Wilhelmsen wrote:
> Jim Newton <jimka at rdrop.com> writes:
>
>
>>I.e., x = if something:
>> expr1
>> else:
>> expr2
>
>
> Try exploiting that a boolean expression evaluates to 0 or 1:
>
> x = (expr1, expr2)[something];
>
> Keep in mind that this might break on some later release of Python if
> they decide to make boolean its own type, but at least it works for
> 2.3.3.
More information about the Python-list
mailing list