[Python-Dev] conditional expressions?

Guido van Rossum guido@python.org
Tue, 16 Oct 2001 09:17:37 -0400


> [Greg Ewing]
> > Has the "x if c else y" idea been totally rejected?
> > It doesn't require a new keyword, or parentheses to
> > disambiguate from an if statement.
> 
> I was its only fan within PythonLabs, and I was lukewarm.  The trick is to
> view "if c else" as a new short-circuiting infix binary operator (for each
> c), and then it makes great-- even elegant --sense.  But it's apparently a
> major strain to see it that way.  It had at least one sworn mortal enemy,
> and I think Fred Drake was so upset at the idea that he couldn't speak.

Also I believe it would create a parsing problem in list
comprehensions; compare these two:

    [x for x in range(10) if prime(x)]  # 'if' is part of list compreh.
    [x for x in range(10) if small else range(100)]  # 'if-then' construct

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