ternary operator

Paul Rubin phr-n2003b at NOSPAMnightsong.com
Thu Feb 6 17:00:44 EST 2003


"John Roth" <johnroth at ameritech.net> writes:
> > value = (lambda: valTrue, lambda: valFalse)[not selector]()
> 
> Of course you can do it that way. Now try explaining that syntax
> to your average COBOL programmer attempting to learn a more
> modern language.

Yeah.  I've never understood this obsession with keeping conditional
expressions out of Python.  They didn't confuse people in Algol-60 and
I think Pascal (designed as newbie language from the beginning) had
them too.

Of course Python doesn't NEED conditional expressions.  It also
doesn't need to recognize the digits 8 or 9, since you can enter every
numeric constant in octal without using those digits.  But if the most
frequently asked question in c.l.py is how do you enter a number in
decimal instead of octal, and the answer is always "you can't, but you
don't really need to" followed by long threads exchanging favorite
contorted workarounds for the problem, then maybe, just maybe, the
people who keep asking how to do it really have identified a
legitimate missing capability in the language.  Sigh.




More information about the Python-list mailing list