[Python] getting size of primitive data types in python

Discussão em 'Python' iniciado por Stack, Julho 21, 2025.

  1. Stack

    Stack Membro Participativo

    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++)

    Continue reading...

Compartilhe esta Página