For review: PEP 308 - If-then-else expression
Evan
evan at 4-am.com
Sat Feb 8 12:38:05 EST 2003
Here's a totally new direction: let's get rid of the chaining and
precedence issues, and make an n-way conditional, not a ternary.
{if cond1: expr1, default}
{if cond1: expr1, cond2: expr2, default}
etc.
Obviously, comma precedence with the braces works the same way as in a
literal dict.
Examples based on the thread of discussion:
x = {if a < 0: 'negative', a > 0: 'positive', 'zero'}
if {if callable(obj): obj(), alttest()}:
roots = [{if x > 0, sqrt(x), '?'} for x in l]
Cheers,
Evan @ 4-am
More information about the Python-list
mailing list