When storing a bool in memcached through python-memcached I noticed that it's returned as an integer. Checking the code of the library showed me that there is a place where isinstance(val, int)
is checked to flag the value as an integer.
So I tested it in the python shell and noticed the following:
>>> isinstance(True, int)
True
>>> issubclass(bool, int)
True
But why exactly is bool
a subclass of int
?
It kind of makes sense because a boolean basically is an int which can just take two values but it needs much less operations/space than an actual integer (no arithmetics, only a single bit of storage space)....