Conditional operator in Python?

Ben Wolfson wolfson at midway.uchicago.edu
Sun Apr 1 00:25:44 EST 2001


In article <3AC6B9C5.68EFC041 at alcyone.com>,
Erik Max Francis  <max at alcyone.com> wrote:
>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).

Easily, if unreadably, solved: (condition and (a,) or (b,))[0]



-- 
Barnabas T. Rumjuggler
You do not use a macintosh instead you use a tandy
Kompressor break your glowstick Kompressor eat your candy



More information about the Python-list mailing list