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

Anthony Baxter anthony at
Sat Feb 8 06:34:31 CET 2003

I was sort of ambivalent about this until I saw the examples section:

>>> Guido van Rossum wrote
>         x if C else y if D else z <==> x if C else (y if D else z)
>         x or y if C else z        <==> (x or y) if C else z
>         x if C else y or z        <==> x if C else (y or z)
>         lambda: x if C else y     <==> lambda: (x if C else y)
>         x if C else lambda: y     <==> SyntaxError
>         x if C else y, z          <==> (x if C else y), z
>         x, y if C else z          <==> x, (y if C else z)

This is utterly nasty, and _painful_ on the eyes and brain to read
and parse.

I _like_ the fact that Python doesn't have 15 different ways to spell
"if" (like another P language). The trailing "unless" clause was actually
one of the things that drove me away from Perl, and this proposed addition
to the language really brings up unpleasant memories.

I've been programming in python now for something around 10 years, and
I can honestly say I've _never_ said "gee, I wish python had a ternary
operator". Sure, it might produce more compact code, but in this case it's
clearly at the expense of readability. So I'm a definite -1 on this.


Anthony Baxter     <anthony at>   
It's never too late to have a happy childhood.

More information about the Python-list mailing list