[Python-Dev] Adding a conditional expression in Py3.0

Guido van Rossum guido at python.org
Tue Sep 20 21:17:41 CEST 2005

On 9/20/05, Terry Reedy <tjreedy at udel.edu> wrote:
> "Guido van Rossum" <guido at python.org> wrote in message
> > and +1 on adding a conditional expression. I believe (y if x else z)
> > was my favorite last time, wasn't it?
> No.  That was your original proposal, which you later rejected.

Thanks for setting me straight; upon re-reading the PEP I couldn't
even remember which one I favored at the time!

> Your final 'favorite' was apparently (at the top)
> "Proposal
>     The proposed syntax is as follows:
>     (if <condition>: <expression1> else: <expression2>) " (+ elif parts)
> selected from
> "Summary of the Current State of the Discussion
>    Groups are falling into one of three camps:
>     1.  Adopt a ternary operator built using punctuation characters:
>             <condition> ? <expression1> : <expression2>
>     2.  Adopt a ternary operator built using new or existing keywords.
>         The leading examples are:
>             <condition> then <expression1> else <expression2>
>             (if <condition>: <expression1> else: <expression2>)
>     3.  Do nothing."
> Given the later addition of generator expressions with mandatory
> parentheses , the mandatory-parentheses version of a conditional expression
> looks less strange to me than it did then ;-).  So I could happily use it
> even though I may still lean toward the other option 2 version (then-else)
> due to  its not needing ':'s or a third elseif term for chaining.

I think I'd prefer (if <expr> then <expr> else <expre>) i.e. no
colons. None of the other  expression forms (list comprehensions and
generator expressions) involving statement keywords use colons.

> *If* you want general community input, I would suggest a runoff ballot with
> those four choices (and a summary of pros and cons of each), or fewer if
> you see any as unacceptible.

If there's one thing I've learned from the PEP 308 vote, it is that
votes for language don't work. I prefer some discussion on Python-dev
after which I pick one.

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list