For review: PEP 308 - If-then-else expression

Dan Bishop danb_83 at yahoo.com
Fri Feb 7 19:20:49 EST 2003


Guido van Rossum <guido at python.org> wrote in message news:<mailman.1044638179.4983.python-list at python.org>...
> Given that if-then-else expressions keep being requested, I hereby put
> forward a proposal.  I am neutral on acceptance of the proposal; I'd
> like the c.l.py community to accept or reject it or come up with a
> counter-proposal.  Please understand that I don't have a lot of time
> to moderate the discussion; I'll just wait for the community to
> discuss the proposal and agree on some way to count votes, then count
> them.
[snip]
>     The proposed syntax is as follows:
> 
>         <expression1> if <condition> else <expression2>
[snip]
>     To disambiguate this in the context of other operators, the
>     "if...else" part in the middle acts like a left-associative binary
>     operator with a priority lower than that of "or", and higher than
>     that of "lambda".

I like the idea but hate the (imho) convoluted order of the condition
and expressions.
 
> Alternatives
[snip]
>     If we could live with adding a new keyword, we could use:
> 
>         if <condition> then <expression1> else <expression2>
>
>     Apart from the problem of introducing a new keyword for a minor
>     feature, this also suffers from ambiguity at the start of a
>     statement; for example:

In the other thread, I suggested the syntax

(if condition: expression1 else expression2)  # parentheses are
required

which introduces no new keywords or punctuation, and doesn't suffer
from the ambiguity you described.




More information about the Python-list mailing list