For review: PEP 308 - If-then-else expression
gustav at morpheus.demon.co.uk
Sat Feb 8 23:28:08 CET 2003
"Andrew Dalke" <adalke at mindspring.com> writes:
> As I mentioned elsewhere, I've scanned the Linux kernel for use
> of the ?: operator. It isn't used all that often, and most cases can
> be implemented in Python with the
> [false, true][expr comparison value]
> construct or with the
> x = y or default_value
Actually, in C, I often find that I *can't* use the ternary operator,
because what I want is a default. So
x = y or default
is more useful to me. (But Python already has that).
> 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.
This signature intentionally left blank
More information about the Python-list