Short if

Ezequiel, Justin j.ezequiel at spitech.com
Wed Jul 7 06:18:24 EDT 2004


> > Does Python have a short if like C or PHP:
> >
> >   bool = false
> >   string = 'This is ' + (( bool ) ? 'true' : 'false')
> 
>     bool = False   # check capitalisation!
>     string = 'This is ' + ('false','true')[bool]

How about...

>>> bool = 1
>>> string = 'this is ' + (bool and 'true' or 'false')



More information about the Python-list mailing list