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

Sean Ross sross at
Sat Feb 8 18:30:47 CET 2003

> Sean> And, of course
> Sean>     if if C then x else y:
> Sean> stuff...
> Sean> is worse than both.
> I'm not sure, actually.  At least it alerts the reader that something
> is going on :-)

Now, that you mention it, yeah, it does alert the reader that something is
going on.
I suppose it's just the repitition of 'if' I don't care for...

How about:

   if when C then x else y: stuff...


   if when C, x else y: stuff...


Someone suggested the latter formulation would cause difficulties in lists
and tuples...'s tough to think of something that would satisfy everyone isn't

> Sean> Personally, I don't mind
> Sean>  if (y, x)[C]:
> Sean> stuff...
> Sean> although I don't consider it to be either obvious or clear.
> I *do* mind it, for two reasons:
> 1) It puts the false condition ahead of the true condition.

Yeah. I don't like that either, and:
    if {True: x, False:y}[C]: stuff...
(as someone else suggested) doesn't appeal to me, although it does address
your first concern.

> 2) It evaluates both alternatives even though only one is needed.


> Andrew Koenig, ark at,

More information about the Python-list mailing list