Update to PEP308: if-then-else expression

Raymond Hettinger vze4rx4y at verizon.net
Tue Feb 11 17:04:20 EST 2003


[Raymond Hettinger
> > * (if <condition>: <expression1> else: <condition2>) is in vogue.

[Samuele Pedroni]
> - 10

Wow, that's pretty strong.
To make it stick, it helps to post your reasons.
My own reasons for avoiding this one are:

* you have to look twice to see that you're dealing
   with an expression rather than an if-statement

* when looking at an expression, my mind is trained
   to see alpha characters as a variable or function name

* the enclosing parenthesis requirement feels wrong

* there is an unpleasant Smalltalk flavor to having
   a single, expression operator take two keywords
   followed by colons and parameters.  There is nothing
   else like it in Python (it doesn't fit).

All of these problems are solved by using punctuation
instead of keywords:

    c ?? a || b          c ? a : b        c ? a ! b


Raymond Hettinger






More information about the Python-list mailing list