5 Réponses
+ 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)