if does not evaluate

Tor Iver Wilhelmsen tor.iver.wilhelmsen at broadpark.no
Sun Jun 6 03:17:00 EDT 2004


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