-7

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
  • 11
  • 1
  • 1
  • 1

4 Answers4

3

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

wim
  • 338,267
  • 99
  • 616
  • 750
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
  • 260,549
  • 28
  • 431
  • 505
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
  • 4,033
  • 2
  • 24
  • 44
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
  • 11,263
  • 21
  • 87
  • 181