0

While the size of int() instance is 24 bytes in both python 2 and python 3, can anyone help understand why there is this difference

Python 2.7:

import sys
sys.getsizeof(5)

Output : 24

Python 3.6:

import sys
sys.getsizeof(5)

Output : 28

data_set
  • 339
  • 2
  • 15
  • 1
    You just showed that the size is *not* 24 in both python 2 and 3. The size also probably depends on platform and whether this is a 64-bit version of Python. – interjay Nov 20 '17 at 15:05
  • In Python 2, look at `sys.getsizeof(5L)`. – glibdud Nov 20 '17 at 15:06
  • In Python3, look at `sys.getsizeof(int(1e100))` – Mad Physicist Nov 20 '17 at 15:07
  • Py2 and Py3 mean very different things with `int`. You can always look at the source code to see how the different structures are implemented. Py2 `int` is a fixed-size structure, while Py3 `int` is definitely not. – Mad Physicist Nov 20 '17 at 15:08
  • 1
    Was going to add this as an answer, but it got closed. From [What’s New In Python 3.0](https://docs.python.org/3.0/whatsnew/3.0.html#integers): _PEP 0237: Essentially, long renamed to int. That is, there is only one built-in integral type, named int; but it behaves mostly like the old long type._ So, more appropriate to compare `5` in Python 3 to `5L` in Python 2. – glibdud Nov 20 '17 at 15:11

0 Answers0