0
>>> x=float(12.345)
>>> x
12.345
>>> sys.getsizeof(x)
16
>>> sys.getsizeof(12.345)
16

Here 16 is of the unit of byte? But in the document it's of 64 bits the float

python 3.5.1 32bits Windows 7 64

Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61
  • 2
    Possible duplicate of [How to check the size of a float in python?](http://stackoverflow.com/questions/8216088/how-to-check-the-size-of-a-float-in-python) – glls Jun 16 '16 at 03:37

2 Answers2

3

sys.getsizeof() returns the memory size of an instance of the float type. In addition to the 8 bytes used by the 64-bit IEEE representation of a float, additional memory is used for reference count, a pointer to type information, etc.

casevh
  • 11,093
  • 1
  • 24
  • 35
  • Nitpick: in this case, you could lose the `etc.`. At least for CPython, "value, refcount and type pointer" is an exhaustive list of what's stored for a float. – Mark Dickinson Jun 16 '16 at 10:13
0

The memory space consumed by a python variable depends on the what version of python you have ie. 32 bit or 64 bit platform.

Coming to float representation. A float in 32 bit python consumes 16 bytes of memory while for 64 bit it consumes 24 byte of memory.