Another conditional expression candidate (PEP 308)
from_usenet at alandaniels.com
Mon Feb 10 05:48:35 CET 2003
On Sun, 09 Feb 2003 23:22:21 GMT, Evan <evan at 4-am.com> wrote:
>x = (if a > 0: 'positive' elif a == 0: 'zero' else: 'negative')
>The parentheses and 'else:' clause are mandatory. Leave them off and
>you get a SyntaxError.
Am I missing something? The whole point of a ternary operator is to
save you extra typing. This just seems to take everything you'd
typically write and squish it into one line.
Also, I think this would also be VERY confusing to new users.
This would be legal syntax:
result = if cond: x else: y
result = if cond:
...would be illegal (it certainly is *now*, anyway). So to implement
this would require changing the fact that "if" blocks are not
expressions. Do I understand this correctly? Thanks.
More information about the Python-list