I am learned about getsizeof() operator, and cannot understand why:
import sys
A=[(1,2,3,4)]
B=[()]
print(sys.getsizeof(A))
print(sys.getsizeof(B))
both print 64 . This is size in bytes but why isn't it changing?
I am learned about getsizeof() operator, and cannot understand why:
import sys
A=[(1,2,3,4)]
B=[()]
print(sys.getsizeof(A))
print(sys.getsizeof(B))
both print 64 . This is size in bytes but why isn't it changing?
sys.getsizeof()
The size that actually goes up in memory.
so, empty string (like "" ) occupies 49bytes.
print(sys.getsizeof(''))
print(sys.getsizeof(en))
# result
# 49
# 76
Yes! because you are passing both tuple. if want to check the size you need to pass the A values as list and B value as tuple. like this `
import sys
A=[1,2,3,4]
B=[()]
print(sys.getsizeof(A))
88
print(sys.getsizeof(B))
64
` here is some more examples:
import sys
a =[1, 2]
b =[1, 2, 3, 4]
c =[1, 2, 3, 4]
d =[2, 3, 1, 4, 66, 54, 45, 89]
print(sys.getsizeof(a))
print(sys.getsizeof(b))
print(sys.getsizeof(c))
print(sys.getsizeof(d))
it's just a minimal size of list object.
import sys
A=(1,2,3,4)
A_LIST=[(1,2,3,4)]
B=[()]
B_2=[(),()]
print(sys.getsizeof(A))
print(sys.getsizeof(A_LIST))
print(sys.getsizeof(B))
print(sys.getsizeof(B_2))
#72
#64
#64
#72
Here you can find out more about sizes