condition and True or False

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Thu May 6 03:14:23 EDT 2010


In message
<685761fe-b052-4d89-92d3-17d1f2a39e34 at p2g2000yqh.googlegroups.com>, Paul 
McGuire wrote:

> While sifting through some code looking for old "x and y or z" code
> that might better be coded using "y if x else z", I came across this
> puzzler:
> 
>     x = <boolean expression> and True or False

I suspect the “boolean expression” isn’t actually evaluating to a Boolean at 
all, this is simply a long-winded way of converting values that Python 
treats as “false” (e.g. None, 0, what else?) to actual False, and everything 
else to True.



More information about the Python-list mailing list