[Tutor] Re: Are you allowed to shoot camels? [kinda OT]

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Fri Feb 4 12:14:43 CET 2005

Alan Gauld wrote:
>>I also wish Python would take up the C ternary operator 
>>which is also quite clear and elegant.
> :-)
> You joke I assume? ':?' is clear? Its succinct but also 
> prone to abuse. I don't think the Python equivalent 
> foo = x and y or z
> is much less elegant than
> foo = x ? y : z

You must be joking too... You think that

x and y or z

is as clear as

x ? y : z

even though the former is just a hack that was not meant to be used as 
such, while the latter is a well-documented feature that is designed to 
do what it does?

Ugly as I think it is, I could live with that. But it's worse:

x and y or z

doesn't even work if y evaluates to False. That alone makes me never 
want to use the construct: whether the expression evaluates to y or z 
should depend on the value of x, not the value of y or z.

As far as I'm concerned, the lack of a proper ternary if/then/else 
operator is a wart in the otherwise very clean design of Python. The 
lack of a switch statement too, but to a much lesser degree.

"Codito ergo sum"
Roel Schroeven

More information about the Tutor mailing list