PEP 308: Alternative conditional operator forms

Michele Simionato mis6 at
Tue Feb 11 20:42:22 CET 2003

Dave Brueck <dave at> wrote in message news:<mailman.1044977569.32211.python-list at>...
> On Tue, 11 Feb 2003, Michele Simionato wrote:
> >
> > (if C: x else: y)
> >
> > that I dislike since
> >
> > 1) overload "if"
> Out of curiosity, in what way is "if" overloaded? The reason I like 'if'
> in this context is because it means the _exact_ same thing it does in an
> if-statement: a condition is about to be checked in order to make a binary
> desicion. Because it means the same thing as it does in an if-statement,
> it's so much easier to guess the meaning if you're not familiar with it.
> The colon and (usually) indentation is what marks the beginning of a block
> of code under an 'if', not the 'if' itself.
> -Dave

As I said in some other thread, I want a clear distinction between the
"if" statement and the conditional expression. They cannot be distinguished
by a parenthesis only:

if C: print x
else: print y

is correct whereas

(if C: print x
 else: print y)

would be a syntax error! (I am quoting an example from another poster).
Max M. said (and I 100% agree with him):

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
     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. """

Moreover, I hate to call a function with

f((if C: x else: y))

and I hate the next unavoidable step 

(try: X except: Y)


Why to go over all this trouble when we have

C then x else y

without parenthesis, colons, if and with "then" not a keyword ?

More information about the Python-list mailing list