None
in Python is a reserved word, just a question crossed my mind about the exact value of None
in memory. What I'm holding in my mind is this, None
's representation in memory is either 0 or a pointer pointing to a heap. But neither the pointer pointing to an empty area in the memory will make sense neither the zero value. Because when I tested the following:
>>> None.__sizeof__()
16
It turns out that None
consumes 16 bytes and that's actually too much for simply an empty value.
So what does
None
actually represents in memory?
None
references some Python object of the NoneType
, actually the only instance of its kind. Since it’s a Python object—like literally every other thing—it’s not just the raw content what is stored about also the additional object information like its type.
Every object has this overhead; that’s why integers start with a size of 28 for example. You cannot change this, it’s an implementation detail of Python and its type system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With