PEP 308: ternary operator

Terry Hancock hancock at anansispaceworks.com
Sat Feb 22 02:05:40 EST 2003


Raymond Hettinger wrote:
> Also, the use of c?a:b in other languages is an important
> consideration so that skills are transferrable both to and
> from Python.   That syntax is used in enough other places
> to make it a valuable thing to know.

As far as I am concerned, the only relevance to this is in considering that 
there *should be* a ternary operator, which I agree with, if it can be done 
in a readable way.

I would also say it is a good argument for not using, say:

<cond>: <a>?<b>

which would surely be annoying for people switching back and forth!

But that hasn't been proposed, of course.

I simply think that Python should use *words* and not symbols for this 
concept, which is neither directly derived from mathematical notation, nor 
frequently enough used for the few keystrokes saved to be worth the loss in 
clarity.  I would in fact use this structure quite a lot in Zope web pages, 
and perhaps 1 or 2 times in a typical 200 line Python module I might write. 
 I would never expect to need to nest them more than 3 deep or so, at most 
(and I would consider it bad style to go much beyond that).  So I simply 
can't see any practical reason not to use a keyword style, whereas the 
symbolic styles are both harder to remember and to look up.

Cheers,
Terry

-- 
Anansi Spaceworks
http://www.anansispaceworks.com




More information about the Python-list mailing list