Short if

Thomas Lindgaard thomas at it-snedkeren.BLACK_HOLE.dk
Wed Jul 7 13:13:47 CEST 2004


On Wed, 07 Jul 2004 11:14:45 +0200, Thomas Lindgaard wrote:

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

Ok, I see that this is not really the language for short ifs (writing
('true', 'false')[bool] does not strike me as being very readable, so I
think I'll revert to the long version).

Used carefully, though, I think that the ternary operator is very useful.

-- 
Regards
/Thomas




More information about the Python-list mailing list