Update to PEP308: if-then-else expression

Max M maxm at mxm.dk
Tue Feb 11 10:46:16 EST 2003


Samuele Pedroni wrote:
> "Raymond Hettinger" <python at rcn.com> ha scritto nel messaggio
> news:mailman.1044943071.22634.python-list at python.org...
> 
>>* (if <condition>: <expression1> else: <condition2>) is in vogue.
> 
> - 10

I do like the ternary operator, but strongly dislikes the above syntax.

Normally an if sentence has the form:

if x==21:
     result = x*2
else:
     result = 42

But now suddenly the if should act like some kind of function and return 
a value?

result = (if x==21: x*2 else: 42)

And what is this with parens that has to be there? This is so 
inconsistent with how parens are used normally in Python. Normally they 
are only needed for tuples, functions and multiline statements.

Should there really be made an inconsistency like that, for a marginal 
featue like this?

One of the great thing about the ternary operator is it's tersenes. That 
is completely gone with that syntax.

So I must say that I *strongly* favor:

result = x==21 ?? x*2 || 42


-- 

hilsen/regards Max M Rasmussen, Denmark

http://www.futureport.dk/
Fremtiden, videnskab, skeptiscisme og transhumanisme





More information about the Python-list mailing list