Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting size of primitive data types in python

Tags:

python

I am having a lot of confusion using the sys.getsizeof function in python. All I want to find out is that for say a floating point value, is the system using 4 or 8 bytes (i.e. single or double precision in C terms).

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 simply find out the how many bytes are actually used for the floating point representation. I know it should be 8 bytes but how can I verify this (something like the sizeof operator in C++)

like image 452
Luca Avatar asked Mar 16 '18 10:03

Luca


1 Answers

import ctypes
ctypes.sizeof(ctypes.c_double)
like image 173
Sven Nyström Avatar answered Oct 12 '22 11:10

Sven Nyström