Another conditional expression candidate (PEP 308)
Evan
evan at 4-am.com
Mon Feb 10 08:58:47 EST 2003
Alan Daniels wrote:
> Am I missing something? The whole point of a ternary operator is to
> save you extra typing.
No. If that were the whole point then the idea would have died long
ago. It's about clarity of expression.
> Also, I think this would also be VERY confusing to new users.
> This would be legal syntax:
>
> result = if cond: x else: y
>
> But this...
>
> result = if cond:
> x
> else:
> y
>
> ...would be illegal
This is part of why I suggested mandatory parens. Then both of these
are legal, and there is no confusion:
result = (if cond: x else: y)
result = (if cond:
x
else:
y)
Cheers,
Evan @ 4-am
More information about the Python-list
mailing list