For review: PEP 308 - If-then-else expression

Carlos Ribeiro cribeiro at mail.inet.com.br
Mon Feb 10 15:16:20 CET 2003


On Sunday 09 February 2003 22:27, Paul Foley wrote:
> [cond1 -> expr1; cond2 -> expr2; ...; True -> default]  :-)

Nice proposal. But the default condition deserves a better way to be signaled:

[cond -> expr1; cond2 -> expr2; else default]

This way, the simple conditional expression would be written as:

[cond -> expr1; else default]

Of course, the 'else' in the default condition is there for readability 
reasons alone. But it's elegant, and it looks Pythonic. Note also that it's 
quite easy to disambiguate it from the list constructors.

Some examples based on what was presented in the list:

[Delta > 0 -> "Real roots"; else "Imaginary roots"]
[divisor != 0 -> val/divisor; else 0]
[Value < 0 -> clRed; else clBlack]

I think this one has a chance to pass.


Carlos Ribeiro
cribeiro at mail.inet.com.br





More information about the Python-list mailing list