Short if

Peter Hickman peter at semantico.com
Wed Jul 7 12:00:32 CEST 2004


Thomas Lindgaard wrote:

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

As elegant as that may seem it is all too easy to abuse. Especially when people 
start to nest them. Code can quickly become unreadable. I almost always have to 
convert nested ?:'s to proper if then else constructs when I come across them in 
Perl.

But then I prefer readability over byte misering. Python is a language which is 
founded on readability, lets not forget that.



More information about the Python-list mailing list