Another conditional expression candidate (PEP 308)
Evan
evan at 4-am.com
Mon Feb 10 09:17:28 EST 2003
Roy Smith wrote:
> Why is the else: manditory? Why not have it return None if none of the
> conditions are true?
Firstly, because while it is clear to *you* that "if x: 1" will be None
if 'x' is false, it isn't necessarily clear to someone who is new to
Python or who never uses conditional expressions. Your code is now less
readable.
Secondly, parse this for me (assuming that those who object to mandatory
parentheses win):
x = if c1: e1 elif c2: if c3: e3 else: e4
Now try:
x = if c1: e1 elif c2: if c3: e3 else: None else: e4
You wouldn't write it without clarifying parens? Someone would.
My point is that if Guido is going to agree to add this controversial
new feature to Python, the result should be absolutely
no-thought-required readable and consistent. Nothing optional, apart
from the inherent n-way optionality of the elif: clauses. No precedence
questions. No Corner Case. Dead simple.
Cheers,
Evan @ 4-am
More information about the Python-list
mailing list