Short if

Tor Iver Wilhelmsen tor.iver.wilhelmsen at
Wed Jul 7 17:32:47 CEST 2004

Thomas Lindgaard <thomas at> writes:

> writing ('true', 'false')[bool] does not strike me as being very
> readable,

... which makes it a perfect candidate for the ?: ternary operator.


(Also, if the variable "bool" can hold some non-boolean value you want
to check, use the builtin bool() function, as someone was nice to
point out to me the last time a similar question came up.)

More information about the Python-list mailing list