I have below program to print the id and size of list and it's elements.
import sys
a=[1,2,3]
print(id(a))
print(id(a[0]))
print(id(a[1]))
print(id(a[2]))
print("=================")
print(sys.getsizeof(a))
print(sys.getsizeof(a[0]))
print(sys.getsizeof(a[1]))
print(sys.getsizeof(a[2]))
which prints:
139954746492104
10914496
10914528
10914560
=================
88
28
28
28
Few Questions:
- The size of a[0] is 28. When I multiply 28*3=84, how size of list a is 88?
- When I subtract address of a[1] - a[0] i.e. 10914528 -10914496 = 32 How I am getting 28 when I use size of function?
idofais 139954746492104. Then howidofa[0]is 10914496?