For review: PEP 308 - If-then-else expression
Michele Simionato
mis6 at pitt.edu
Sat Feb 8 18:23:52 EST 2003
Evan <evan at 4-am.com> wrote in message news:<1gb1a.33499$yb.1988258 at twister.austin.rr.com>...
> 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
Not convincing. For multiple choices one should use a dictionary. I am favorable
to a ternary operator but against a "case" operator.
M.
More information about the Python-list
mailing list