SoFunction
Updated on 2024-11-12

Example of the size of memory space occupied by python's basic data types

There is a big difference in the amount of memory space occupied by basic data types in python and other languages.

import sys
a = 100
b = True
c = 100L
d = 1.1
e =""
f = []
g =()
h = {}
i = set([])

print " %s size is %d "%(type(a),(a))
print " %s size is %d "%(type(b),(b))
print " %s size is %d "%(type(c),(c))
print " %s size is %d "%(type(d),(d))
print " %s size is %d "%(type(e),(e))
print " %s size is %d "%(type(f),(f))
print " %s size is %d "%(type(g),(g))
print " %s size is %d "%(type(h),(h))
print " %s size is %d "%(type(i),(i))

 <type 'int'> size is 12 
 <type 'bool'> size is 12 
 <type 'long'> size is 14 
 <type 'float'> size is 16 
 <type 'str'> size is 21 
 <type 'list'> size is 36 
 <type 'tuple'> size is 28 
 <type 'dict'> size is 140 
 <type 'set'> size is 116 

The above example of the size of the memory space occupied by the python basic data types is all that I have shared with you, and I hope it will give you a reference, and I hope you will support me more.