Apparently integers cost 24 bytes in Python. I can understand that it does so because of the extra bells and whistles of representing unbounded number. However it looks like boolean data types also cost whopping 24 bytes even though it can only ever represent one of two possible values. Why? What extra data might need to be stored aside from 1 bit representing True
or False
?
Note: I'm not asking for best way to store bools. I'm already aware of NumPy, BitArray, etc. from other answers. My question is why, not how.
numpy
with it). – Subjoinderlong
, the actual bignum type, has even bigger instances. – GryphonTrue
andFalse
are singletons, so it's not wasting very much memory! – Subjoinder