Ternary Operator

Stefan Kirchberg sk at gluit.de
Fri May 18 11:45:27 EDT 2001


Hi,

I just read section 4.16 of The Whole Python FAQ
(http://www.python.org/doc/FAQ.html#4.16). It states that as an
equivalent to C/C++'s
        a? b : c
expression, the Python expression
        a and b or c
has a flaw if b evaluates to 0 (false) and the expression
        (a and [b] or [c])[0]
being a possible solution. Unfortunately, the latter one seems
kind of obfuscated to me...

Now, how about
        [b,c][not a]
-?

Maybe this one's just frequently asked... but I didn't find it
in the FAQ :-)

Stefan

---
Stefan Kirchberg  -- sk at gluit.de



More information about the Python-list mailing list