PEP 308: ternary operator

Damien Morton newsgroups1 at bitfurnace.com
Thu Feb 20 08:05:22 EST 2003


The C ternary operator is quite easy to remember.

<question> ? <answer> : <alternative_answer>

<question> <questionmark> <answer> <separator> <alterantive_answer>

Im not sure the colon is the best character to separate two alerternative
answers, but thats the way it is.

In english it looks like this:

"Will you come to my place? bouncy bouncy, or no bouncy bouncy"


"Terry Hancock" <hancock at anansispaceworks.com> wrote in message
news:jx_4a.12853$YU4.1082191 at newsread1.prod.itd.earthlink.net...
> (I've not been reading c.l.py for a few days, so I'm not sure which branch
> of this thread to reply to)
>
> I have always hated C's ternary operator syntax!  I never used it that
> much, and every time I did I had to look up the syntax.  I REALLY hope
> Python does not simply adopt this syntax, as I think it will go on
> torturing newbies and casual programmers like myself if it does.  Here's
> why it bothers me:
>
> 1) Is it <cond>? <a>:<b> or <cond>: <a>?<b>
> I can never remember this!
>
> 2) Is it <a> ? <cond>: <b> or <cond>:<a>?<b>, or how about <a>:<cond>?<b>
> They all make exactly the same amount of sense to me. (Which is to say,
not
> much).
>
> Note that I am not objecting to the functionality, but rather the symbols
> used to encode it.  I find them highly arbitrary.









More information about the Python-list mailing list