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

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?

8/13/2019 1:30:53 PM

Seb TheS

5 Answers

New Answer

+4

https://docs.python.org/3/library/sys.html#sys.getsizeof https://code.sololearn.com/cRP2WcTRdaWc/?ref=app

+2

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

+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

+1

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

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)