[Python-Dev] Trinary Operators
Guido van Rossum
guido@python.org
Thu, 06 Feb 2003 14:49:23 -0500
> If this is just for fun, why stop with just "trinary"?
(Which BTW is a non-word; the correct term is "ternary".)
> How about one of the following (depending on ease of parsing)?
> These look even more like list comprehension.
>
> x = (e1 if c1 e2 if c2 e3 if c3 ... else d)
Doesn't parse. The concatenation of two expressions is not
always distinguishable from a single expression: consider c1 = f and
c2 = (1, 2).
> x = (e1 if c1 else e2 if c2 else e3 if c3 ... else d)
That works.
--Guido van Rossum (home page: http://www.python.org/~guido/)