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

Paul Moore p.f.moore at gmail.com
Fri Sep 23 16:55:11 CEST 2005


On 9/20/05, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Basically, I'm +1 on the original PEP 308 form because it reads more naturally
> (and more like LC's and GE's) to me in expression contexts, and +0 on the
> "if/then/elif/else" form (because I would like a real conditional operator).

I agree that (expr if cond else expr) fits far more naturally these
days given the ordering of generator expressions (and list
comprehensions, but they were around when PEP 308 was discussed, so I
don't think they work as well as evidence :-)) Also, (expr if cond
else expr) doesn't naturally admit an elif case, reducing complexity
(and the tendency to overuse the construct in complex ways) a little.
And it doesn't need a new keyword.

I have a vague fondness for this form. I really can't express it very
well, but the if-then-else version just feels a little too "boring and
conventional". I'm sure people will get used to it (heck, we've got
decorators and print >> :-)) but maybe pushing a (mildly)
idiosyncratic form isn't worth opening that can of worms again.

I'm +1 on a conditiona expression. I suspect the time is now right.

I'm +1 on *one* of

    (expr if cond else expr)
or
    (if cond then expr else expr)

With the latter, I don't mind if elif is added or not.

I'm +1000000000 on Guido just making the decision. No more votes, please!

Paul.


More information about the Python-Dev mailing list