For review: PEP 308 - If-then-else expression

Skip Montanaro skip at pobox.com
Fri Feb 7 20:02:35 EST 2003


    Skip> For the times I've needed such a construct

    Skip> <cond> and <expr1> or <expr2>

    Skip> has generally been sufficient.

    Andrew> except that this construct has a subtle pitfall: If <cond> is
    Andrew> true and <expr1> is false, the result is <expr2> instead of
    Andrew> <expr1>.

Well understood.  It's a 90% solution, and for the other 10% where I'd have
to resort to something like

    Andrew>         (<cond> and [expr1] or [expr2])[0]

I punt and use an if statement.

Skip





More information about the Python-list mailing list