When storing bool in memcached via python-memcached, I noticed that it was being returned as an integer. Checking the library code showed me that there is a place where isinstance(val, int) checked to mark the value as an integer.
So, I tested it in a python shell and noticed the following:
>>> isinstance(True, int) True >>> issubclass(bool, int) True
But why bool subclass of int ?
This makes sense because the boolean is basically an int that can only take two values, but it requires a lot less operations / spaces than the actual integer (without arithmetic, only one bit of storage space) ....
python boolean
ThiefMaster Nov 17 '11 at 2:43
source share