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

Anders J. Munch andersjm at
Sun Feb 9 22:13:36 CET 2003

"Andrew Koenig" <ark at> wrote:
> Paul> You know, if the inspiration for this syntax (condition in the
> Paul> middle) is list comprehensions, maybe the thing can be improved
> Paul> by requiring parentheses around the expression:
> Paul>   (x if is_special(x) else y)
> Paul> For some reason I find that clearer than the same thing without
> Paul> the parens.
> I thought of that too, but would hate to have to explain that the
> compiler rejected
>         f(x if is_special(x) else y)
> because you didn't write
>         f((x if is_special(x) else y))

Not a problem.  Just allow
   f(x if is_special(x) else y)

See <news:EEb1a.63692$Hl6.7229914 at> for details.

- Anders

More information about the Python-list mailing list