Skip to content

Instantly share code, notes, and snippets.

@ashwin
Created May 10, 2012 13:57
Show Gist options
  • Save ashwin/2653163 to your computer and use it in GitHub Desktop.
Save ashwin/2653163 to your computer and use it in GitHub Desktop.
Size of objects in Python
# Tried with Python 3.2.2 64-bit
import sys
a = None
sys.getsizeof( a ) # 16
a = 0
sys.getsizeof( a ) # 24
a = 12345678
sys.getsizeof( a ) # 28
a = ""
sys.getsizeof( a ) # 58
a = "hello"
sys.getsizeof( a ) # 68 (2 bytes per letter)
a = []
sys.getsizeof( a ) # 64
a = tuple()
sys.getsizeof( a ) # 48
a = set()
sys.getsizeof( a ) # 224
a = {}
sys.getsizeof( a ) # 272
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment