if-else statement

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sat Jan 10 21:28:47 CET 2009


Scott David Daniels:
>       if checking:
>           my_var = 'string'
>       else:
>           my_var = 'other string'
>
> remember, vertical space only kills trees if printed.

I value clarity a lot. But this is more DRY, sometimes it's almost
equally clear, and you reduce vertical space, packing more code in the
same space, this allows you to see more logic, allowing you to have a
higher level view of the code, so allows you to understand the code
better:

my_var = 'string' if checking else 'other string'

So I think that sometimes it's useful.

Bye,
bearophile



More information about the Python-list mailing list