Update to PEP308: if-then-else expression

Oren Tirosh oren-py-l at hishome.net
Tue Feb 11 10:58:46 CET 2003

On Tue, Feb 11, 2003 at 12:54:45AM -0500, Raymond Hettinger wrote:
> * (if <condition>: <expression1> else: <condition2>) is in vogue.


No new keywords
Reuses existing concepts
Verbose and explicit. A little more typing never hurt anyone.
Inside parens ':' has no other meaning.
Inside parens significant whitespace is disabled. Makes it more natural
to format and indent this across multiple lines. Reduces temptation to 
squash everything into one line.
Concept extends naturally to try/except and other constructs. Not sure
if that's an advantage or not. Could be a slippery slope...

Idea: should be applicable to [],{}, too. Anywhere tok->level >= 1.

> * <condition> ?? <expression1> || <expression2> is a new contender.

> * cond(<condition>, <expression1>, <condition2>) is viable if implemented
>       as a keyword and has short-circuit behavior.  Note, the actual word
>       is still an open question.  iif() got shot down quickly.

Short-circuit behavior seems out-of-place in something that looks like a
function call.

P.S. I am still -0 on the concept as a whole, but if it's done, it should
at least be done right.


More information about the Python-list mailing list