On 27/07/13 05:41, Steven D'Aprano wrote:

It's only a happy coincidence that bool(1) returns True. So does
bool(-9) after all...
It's more than just a happy coincidence. True actually equals 1.

For backwards compatibility, True == 1 and False == 0 had to remain the
case. So the bool type is actually a subclass of int, but restricted to
only two values. The side effect of this is you can do this:

True + 2
=> returns 3

Most of what you said I knew, but I didn't realize it went so far as allowing arithmetic! Now I'm on the side of that being a bad thing.

Booleans should be as distinct from numbers as chars
are from strings... ;-)

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to