(a==b) ? 'Yes' : 'No'

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Apr 1 22:33:28 EDT 2010


On Thu, 01 Apr 2010 08:27:53 -0700, Den wrote about Python's ternary 
operator:

> I've been following this thread for a few days now.  My thoughts are
> that, in view of a long known widely used syntax for this operator,
> python's syntax seems like change for change sake.  If current
> programing paradigm provides that particular trinary operator, why
> should python's be different from the previously well known one.

Yes, I agree, we should be using the previously well known syntax:

condition -> value_if_true, value_if_false

which was introduced by BCPL in 1966.


> For instance, no reasonable language designer would, now, use post-fix
> (I know about Forth) 

Do you also know about Postscript, Factor, Joy and Cat, to mention only a 
few? And also the native language of Hewlett-Packard scientific 
calculators, RPL.



> or allow only +=, -=, /=, etc. assignments ONLY.
> (Just as no reasonable car designer would put the accelerator pedal on
> the left.)  There are conventions which should span products.  Yes
> python has the trinary operator and it's not going to change, but this
> seems like a bit of petulance on the part of the designer.

Unless you have read the PEP that added the operator to the language, and 
the reasons for rejecting the alternatives, you are not qualified to 
guess what Guido's motives for choosing the current syntax are.

http://www.python.org/dev/peps/pep-0308/

You might not like it, but I do, and I like it far more than the ugly and 
hard to understand C syntax. In English (which has existed for much 
longer than C) the question mark punctuation symbol is a sentence 
terminator, not a separator between clauses, so using ? as an operator 
has always looked strange and disturbing to me.




-- 
Steven



More information about the Python-list mailing list