sizeof operator in Python | SoloLearn: Learn to code for FREE!


sizeof operator in Python

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

8/13/2019 1:30:53 PM

Seb TheS

5 Answers

New Answer



You use sys.getsizeof(item) import sys print(sys.getsizeof("Hello"))


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


Well its because there are a couple bells and whistles of consisting of unbounded numbers


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)