📅 2012-May-10 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ python, size ⬩ 📚 Archive
The getsizeof
function from the sys
module can be used to obtain the size of objects in Python. Comparing the size of elementary objects in Python with that in other languages can be quite interesting.
# Tried with Python 3.2.2 64-bit
import sys
= None
a # 16
sys.getsizeof( a )
= 0
a # 24
sys.getsizeof( a )
= 12345678
a # 28
sys.getsizeof( a )
= ""
a # 58
sys.getsizeof( a )
= "hello"
a # 68 (2 bytes per letter)
sys.getsizeof( a )
= []
a # 64
sys.getsizeof( a )
= tuple()
a # 48
sys.getsizeof( a )
= set()
a # 224
sys.getsizeof( a )
= {}
a # 272 sys.getsizeof( a )