-1

I have the following code.

Why is the size of list/tuple lesser than the sum of size of individual elements?

Also why are the sizes of bool and integer 28 bytes?

list_eg = [1,2,3,4,5,"dfd",True,3.1415]
tuple_eg = (1,2,3,4,5,"dfd",True,3.1415)
print(sys.getsizeof(list_eg))
print(sys.getsizeof(tuple_eg))
128
112

print(sys.getsizeof("dfd"))
print(sys.getsizeof(3.1415))
print(5*sys.getsizeof(3))
print(sys.getsizeof(True))
52
24
140
28


print(52+
24+
140+
28)

244
Sreeraj Chundayil
  • 5,548
  • 3
  • 29
  • 68

1 Answers1

1

https://docs.python.org/3/library/sys.html#sys.getsizeof

Only the memory consumption directly attributed to the object is accounted for, not the memory consumption of objects it refers to.

AlanSTACK
  • 5,525
  • 3
  • 40
  • 99