sizeof operator in Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

sizeof operator in Python

Do Python have any functions to perform the C's sizeof operation? Propably not as builtin, but in any modules?

13th Aug 2019, 1:30 PM
Seb TheS
Seb TheS - avatar
5 Answers
+ 4
https://docs.python.org/3/library/sys.html#sys.getsizeof https://code.sololearn.com/cRP2WcTRdaWc/?ref=app
13th Aug 2019, 1:36 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
You use sys.getsizeof(item) import sys print(sys.getsizeof("Hello"))
13th Aug 2019, 1:38 PM
Trigger
Trigger - avatar
+ 2
Actually I was wrong, there is a builtin method to get the size of an object. Any object has a __sizeof__ magic method. (10).__sizeof__() -> 14
15th Aug 2019, 2:06 PM
Seb TheS
Seb TheS - avatar
+ 1
Well its because there are a couple bells and whistles of consisting of unbounded numbers
13th Aug 2019, 1:48 PM
Trigger
Trigger - avatar
0
Thanks, I did not expect Python to require that much memory, even boolean required 14 bits. (maybe because there is no such thing as booleans, just integers)
13th Aug 2019, 1:46 PM
Seb TheS
Seb TheS - avatar