Getting the size of primitive data types in python

I have a lot of confusion using a function sys.getsizeofin python. All I want to know is that, say, a floating point value is a system using 4 or 8 bytes (i.e., single or double precision in terms of C).

I do the following:

import sys

x = 0.0
sys.getsizeof(x)  # Returns 24

type(x) # returns float

sys.getsizeof(float)  # Returns 400.

How can I just find out how many bytes are actually used for the floating point representation. I know this should be 8 bytes, but how can I check this (something like an operator sizeofin C ++)

+4
source share
3 answers

Launch

sys.getsizeof(float)

float, float. , , .

, - float. :

sys.getsizeof(float())

,

float()

0.0, :

sys.getsizeof(0.0)

24 (, , ). CPython ( Python) float ( float), 8 64- CPython 4 32- CPython. (24 - 8 - 8 = 8 , , , 64- CPython), , float.

, Python. :

. ( C Java) . Python ; , , Python, .

- , . , , Python float , ( , 100% ), C.

+6

:

getizeof() sizeof , .

sys.getsizeof , C.

int bit_length().

+2
import ctypes
ctypes.sizeof(ctypes.c_double)
+1
source

Source: https://habr.com/ru/post/1694962/


All Articles