PEP 308: Erik's alternatives list
Gerald S. Williams
gsw at agere.com
Wed Feb 19 11:15:48 EST 2003
"Erik Max Francis" <max at alcyone.com> wrote:
> I. Proposals mentioned in the PEP at some point
[ ...]
> 3. if C: x else: y
I'm starting to really like this one. Basically it's
just interpreting the if/else statement slightly
differently when used in an expression context,
returning the value of the alternative. It gets
its short-circuiting from the normal semantics
of the if statement. Short-circuited expressions
follow ":", just like short-cirtuited statements
do.
Think of it this way: "if" is the embodiment of
two-option short-circuiting.
This would generalize nicely to switch/case if
that construct ever makes it into Python.
-Jerry
P.S.
I still think the current FAQ should show an
alternative that is readable and doesn't need
disclaimers. The following works for me:
def ifelse(x): return x[0]
... ifelse(c and [a] or [b])
More information about the Python-list
mailing list