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

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Mon Apr 5 02:19:12 CEST 2010


On Mon, 05 Apr 2010 12:08:31 +1200, Gregory Ewing wrote:

> Steven D'Aprano wrote:
> 
>> Not according to the PEP. No fewer than 16 alternatives were put to a
>> vote, and with no clear winner (but many obvious losers) Guido made the
>> final decision.
> 
> As I remember, the decision made on the basis of the vote was *not* to
> add a conditional expression at all, because of the fact that there was
> no clear winner.
> 
> It was some time later that Guido suddenly announced out of the blue
> that he was accepting one of the choices that he had earlier said he
> didn't like!
> 
> The ways of the BDFL are strange indeed. :-)


I think what happened was the he got bitten by a subtle bug in the 
previous idiom for the ternary operator:

condition and x or y

will return (x if condition else y) *unless* x itself happens to be a 
false value. This demonstrated that the and/or idiom was not a suitable 
alternative to a short-circuiting ternary operator.



-- 
Steven



More information about the Python-list mailing list