Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sys.getsizeof(int) return 400 bytes

Tags:

python

I intend to get the max size of int

In [1]: import sys
In [2]: sys.getsizeof(int)
Out[2]: 400

Does it mean that the maxint in python is 2**40

However, when I tried

In [5]: types = [int, float, complex, list, tuple, dict, set, True, False, None]
In [7]: [sys.getsizeof(type) for type in types]
Out[7]: [400, 400, 400, 400, 400, 400, 400, 28, 24, 16]

all the data types are 400 bytes.

What does it 400 bytes mean for integer?

like image 279
AbstProcDo Avatar asked Oct 15 '18 07:10

AbstProcDo


1 Answers

In your code you're getting the size of the class not of an instance of the class.

Call int to get the size of an instance, like the following code

>>> sys.getsizeof(int())
24
like image 117
Nidal Avatar answered Sep 23 '22 22:09

Nidal