Conditional expressions (again)

Erik Max Francis max at alcyone.com
Thu Oct 25 13:45:54 EDT 2001


Dale Strickland-Clark wrote:

> However, we already have conditional assignment, which I've used
> several times when I've really had to:
> 
>         x = (b, c)[a]
> 
> Obviously this assumes a is logic 0 or 1 which you can force if
> necessary:
> 
>         x = (b, c)[a != 0]

But this doesn't have the short-circuiting properties of the conditional
operator which was listed as one of the main project.  (I usually use
conditional operators for simple selections between two values, anyway.)

> 
> You can also use the 'iif' function that appears in a number of
> languages:
> 
>         def iif(test, true, false):
>             if test:
>                 return true
>             else:
>                 return false

Or just operator.truth.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Nobody's waited longer than me / To come clean
\__/ Jaki Graham
    Product's Quake III Arena Tips / http://www.bosskey.net/
 Tips and tricks from the absolute beginner to the Arena Master.



More information about the Python-list mailing list