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

Paul Paterson hamonlypaulpaterson at
Sun Feb 9 01:11:40 CET 2003

"Paul Moore" <gustav at> wrote in message
news:y94qpfuv.fsf at
> "Andrew Dalke" <adalke at> writes:
> > I would rather see some better examples of when people would like to
> > use the if/else expression.  People have pointed out that it can do
> > short circuiting, but in the real-life uses I saw in the kernel it
> > didn't make a different if there was short circuiting or not.
> Yes, I thing the short-circuit argument is spurious. No-one has given
> a telling example which needs it.

print sqrt(x) if x >=0 else "Imaginary roots"

This benefits from short-circuiting. It could easily be written with if
statements so it doesn't fit the "telling ... needs" category.

However, for me this is the crux of the matter. Short circuiting pretty much
has to be the justification for implementing this PEP because if you don't
need short-circuiting you can write a trivial three line iff function. But
then if short-circuiting is the main reason then I think I'd rather open up
the general idea of how to implement lazy evaulation in a Pythonic way.

More information about the Python-list mailing list