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

jerf at jerf at
Sat Feb 8 01:00:19 CET 2003

On Fri, 07 Feb 2003 12:14:40 -0500, Guido van Rossum wrote:

> Given that if-then-else expressions keep being requested, I hereby put
> forward a proposal.

I'd say this is not worth doing; the benefits don't outweigh the costs.

As someone else in the thread said, he programmed in C++ for years before
seeing ?:. From what I've seen of people using ?:, it's either so trivial
that it frankly isn't saving anyone anything (a = b ? 1 : 0), or so
complicated (nested ternary operators anyone?) that the user ought to be
stripped of their license to program.

*Because* its use is so rare, it is a frequent an impediment to understanding
code to people who have never, or only rarely, seen it before. In
addition, I find it often surprisingly challenging to follow the order of
operations in such cases if the ?: isn't enclosed by (), just because
there isn't a clear 'natural' order to evaluate expressions with ternary
operators in them.

Finally, and perhaps most controversially, ISTM that people asking for ?:
are, with perhaps a few exceptions, new users of Python who expect it to
be just like the last (or even "only") language they learned. If they want
it that bad, in my experience it's probably because they're abusing it
anyhow; most programmers go a very, very long time without using it even
in languages that have it. One of Python's strengths is its stubborn
refusal to let people hang themselves with it, unless they *really

"-1" is the vernacular, I suppose.

More information about the Python-list mailing list