5

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?

AbstProcDo
  • 19,953
  • 19
  • 81
  • 138
  • 2
    Python's integers are bounded by your RAM only, so there's no "maxint". – ForceBru Oct 15 '18 at 07:05
  • You are seeing the size of the type class for each value in your list, not the max size of integers that can be represented in your interpretor. See https://stackoverflow.com/questions/10365624/sys-getsizeofint-returns-an-unreasonably-large-value for further details. – BoboDarph Oct 15 '18 at 07:07
  • but why `In [13]: sys.maxsize Out[13]: 9223372036854775807` @ForceBru – AbstProcDo Oct 15 '18 at 07:29
  • 1
    @riderdragon, this is the maximum size lists, strings, dicts, and many other containers can have not the maximum supported integer number – Nidal Oct 15 '18 at 07:34

1 Answers1

7

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
Nidal
  • 1,717
  • 1
  • 27
  • 42