For review: PEP 308 - If-then-else expression
Paul Rubin
phr-n2003b at NOSPAMnightsong.com
Sat Feb 8 05:44:40 EST 2003
"Simon Burton" <simonb at webone.com.au> writes:
> +1 from me.
>
> after this:
> "[ x for x in range(10) if is_special(x) ]",
>
> to have this ternary construct:
> "x if is_special(x) else y"
>
> seems reasonable enough.
You know, if the inspiration for this syntax (condition in the middle)
is list comprehensions, maybe the thing can be improved by requiring
parentheses around the expression:
(x if is_special(x) else y)
For some reason I find that clearer than the same thing without the parens.
I still prefer a syntax with the condition first, then the two exprs,
but can live with it either way.
> Perhaps the "else <expr2>" can default to "else None".
I'm neutral on that. It has good and bad points that have been
discussed already.
More information about the Python-list
mailing list