Conditional operator in Python?

Erik Max Francis max at alcyone.com
Sun Apr 1 00:16:53 EST 2001


Emile van Sebille wrote:

> Yes, it comes up.  Generally, except for short-circuiting, the
> solutions
> follow:
> 
> >>> 1 and 2 or 3
> 2
> >>> 0 and 2 or 3
> 3

Yeah, but the short-circuiting exceptions are what make that construct
not worth using, since if used identically as a replacement for a
conditional expression, it won't work when a is 0 (or any other
expression that evaluates to false).

There's a failsafe solution, which is just to use an if: ... else: ...
statement.  I was just wondering why it hasn't crept into Python at some
point, especially since augmented assignments already have, and seem at
the same level of "convenience" (arguably less in fact, since an
augmented assignment is still a statement, not an expression).

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ If I had known, I would have become a watchmaker.
\__/ Albert Einstein
    blackgirl international / http://www.blackgirl.org/
 The Internet resource for black women.



More information about the Python-list mailing list