python - Why is single int 24 bytes, but in list it tends to 8 bytes -


here looking at:

in [1]: import sys  in [2]: sys.getsizeof(45) out[2]: 24  in [3]: sys.getsizeof([]) out[3]: 72  in [4]: sys.getsizeof(range(1000)) out[4]: 8072 

i know int in python growable (can bigger 24 bytes) objects live on heap, , see why object can quite large, isn't list collections of such objects? apparently not, going on here?

this size of object - excluding objects contains:

>>> d = range(10) >>> sys.getsizeof(d) 152 >>> d[0] = 'text' >>> sys.getsizeof(d) 152 >>> d ['text', 1, 2, 3, 4, 5, 6, 7, 8, 9] 

the size of list 1000 elements, in case, 8072 bytes each integer object still 24 bytes. list object keeps track of these integer objects they're not included in size of list object.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -