Short if

Paul Sweeney reverse.ku.oc.issolok at nothypgnal.delrest.co.uk
Wed Jul 7 05:40:04 EDT 2004


> Does Python have a short if like C or PHP:
>
>   bool = false
>   string = 'This is ' + (( bool ) ? 'true' : 'false')
>


If you are really convinced that this is a good road to go down (think of
code readability), you could do

    bool = False   # check capitalisation!
    string = 'This is ' + ('false','true')[bool]

I never liked the C ? operator, always finding code was clearer using the
full if, and this hack is even worse!





More information about the Python-list mailing list