PEP 308: ternary operator

Terry Hancock hancock at
Sat Feb 22 06:58:56 CET 2003

Damien Morton wrote:
> The C ternary operator is quite easy to remember.
> <question> ? <answer> : <alternative_answer>

No, if it were easy to remember, you wouldn't need this mnemonic. I'm not 
saying it's impossible to learn. I'm saying that it's sufficient 
bizarre-looking that if -- like me -- you use it fairly rarely, you have to 
waste time looking it up to be sure.

Consider for example, that the position of the conditional in a standard 
Python if-else structure is right after the condition:

if <question>:

Which suggests the reversed order, doesn't it?  Again, I'm not looking for 
a mnemonic to help me with C (I've pretty much abandoned it for most 
purposes, anyway).  I'm trying to say why I think newbies will be turned 
off by this syntax.

Pointer syntax isn't that hard to remember either -- but it was 
sufficiently confusing to avoid doing it in Python.


Anansi Spaceworks

More information about the Python-list mailing list