-8

I am new to python and i am trying to find size of int, float, double and char of my System. Do we have any syntax to find them?

Anish Agarwal
  • 1
  • 1
  • 1
  • 1

4 Answers4

3

You can look at sys.getsizeof. But it is more complicated than you may think.

wim
  • 302,178
  • 90
  • 548
  • 690
3

int technically has a finite size, but if the result of a computation goes past that size, Python will automatically use an arbitrary-precision long instead. Those are only limited by available memory.

float is an IEEE 64-bit binary floating-point number. Many other languages would call that a double.

double and char don't exist in Python. Python only has one built-in floating-point data type, which is float. Single-character strings are used to represent characters.

user2357112
  • 235,058
  • 25
  • 372
  • 444
1

One can use ctypes.sizeof on ctypes' c_int, c_float, c_double, and c_char types respectively to find the size of the type in bytes.

Ramchandra Apte
  • 3,975
  • 2
  • 23
  • 43
0

These sizes are system independent and represent the number of bytes and precision. A little bit of googling brings up a chart of the primitive data types and their data footprint.

Things get more complicated when concerning data structures and objects.

Jason
  • 10,995
  • 20
  • 83
  • 176