Truthiness

random832 at fastmail.us random832 at fastmail.us
Thu Oct 23 17:24:43 CEST 2014


On Thu, Oct 23, 2014, at 10:56, Simon Kennedy wrote:
> Thanks everyone. That's a thorough enough explanation for me.

You should know, though, that numeric values equal to 1 (and 0 for
False) _are_ == True. This works for dictionary keys, array indexes,
etc. The bool type is actually a subclass of int. Mathematical
operations on it will simply return an int, or float for division -
logical operations and bitwise and/or/xor return bool (bitwise not
returns an int because it returns the values -1 and -2)

So checking if something is == True is the same as checking if it's ==
1, and checking if it's == False is the same as checking if it's == 0.



More information about the Python-list mailing list