Why does the following produce such different results?
>>> sys.getsizeof(int) # same as sys.getsizeof(object), sys.getsizeof(type)
400
>>> sys.getsizeof(1)
28
Is the actual size of the item 1 equal to the size of the object (400) + the size of the actual integer value (28) = 428, or how exactly does the integer/object creation work here?
sys.getsizeof(int)returns the size of the object referenced byint, which in this case, is the class-object for the built-in typeint. That is not the same as the size of any of its instances. Note, integer objects can have different sizes. So comparesys.getsizeof(0), sys.getsizeof(1), sys.getsizeof(10000000000)intis of type<class 'type'>and so are your other examples which is why they are all the same size and1is of type<class 'int'>which is why it's sized 28.