Here’s an example with random integers:
a, b, c, d = 79412623, 56529819571, 10431, 30461
t = (79412623, 56529819571, 10431, 30461)
And their sizes:
import sys
sys.getsizeof(t) # 88
aa, bb, cc, dd = sys.getsizeof(a), sys.getsizeof(b), sys.getsizeof(c), sys.getsizeof(d)
sum([aa,bb,cc,dd]) # 96
Why does the tuple take up less space?
The number returned by
sys.getsizeofdoesn’t include the size of the objects contained by a container.