Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the value of None in memory?

Tags:

python

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?

like image 476
direprobs Avatar asked Feb 14 '16 12:02

direprobs


1 Answers

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.

like image 104
poke Avatar answered Oct 17 '22 23:10

poke