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?
Asked
Active
Viewed 1.3k times
-7
-
take a look at [this](http://stackoverflow.com/questions/9860588/maximum-value-for-long-integer) question. – RickyA Dec 31 '13 at 13:52
-
3It sounds like you're asking about C/C++/Java/C#/... types, not about Python types. Please clarify. – Dec 31 '13 at 13:56
-
There is no such thing as `double` or `char` in Python. – Karl Knechtel Dec 31 '13 at 14:14
-
There is definitely types in python. You can check the type of a variable using the type(varname) command. – gautam1168 May 02 '18 at 03:07
4 Answers
3
You can look at sys.getsizeof
. But it is more complicated than you may think.

wim
- 338,267
- 99
- 616
- 750
-
Note the difference between `sys.getsizeof(int)` and `sys.getsizeof(int())` – wim Dec 31 '13 at 13:55
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