Short if
vincent wehren
vincent at visualtrans.de
Wed Jul 7 05:38:27 EDT 2004
More information about the Python-list mailing list
Wed Jul 7 05:38:27 EDT 2004
- Previous message (by thread): Short if
- Next message (by thread): Short if
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Thomas Lindgaard wrote: > Hello > > Does Python have a short if like C or PHP: > > bool = false > string = 'This is ' + (( bool ) ? 'true' : 'false') > > ? Nope. PEP308 to introduce a ternary operator like idiom has been rejected (see: http://www.sourcekeg.co.uk/www.python.org/peps/pep-0308.html), but you can emulate it: >> bool = False >> s = "This is " + ('false', 'true')[bool] >> print s This is false In this case bool evaluates to 0 and 'false' is at index 0 of the tuple ('false', 'true'). -- Vincent Wehren
- Previous message (by thread): Short if
- Next message (by thread): Short if
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list