PEP 308 - keeping it simple
Ian Parker
parker at gol.com
Sun Feb 16 01:23:17 EST 2003
Several posters have mentioned the FAQ entry:
4.16. Is there an equivalent of C's "?:" ternary operator?
Different implementations of a ternary operator will lead to
embarrassing FAQ entries:
4.16. Is there an equivalent of C's "?:" ternary operator?
Yes, as you know Python is an elegantly simple language and of course
provides a ternary operator equivalent to "c?a:b", although more
long-winded, and requiring parentheses
(if c then a else b)
or
4.16. Is there an equivalent of C's "?:" ternary operator?
Yes, just use a similar construction to an if statement, but swap the
order of the terms around a little to get
a if c else b
which everyone agrees would be a natural way to express a conditional,
if one wasn't already familiar with the order used in if statements.
Let's just go for the C way of doing this so that we can drop the FAQ
entry entirely.
--
Ian Parker
More information about the Python-list
mailing list