Reputation: 71
I'm trying to understand the below snippet.
import sys
variable = 30
print(sys.getsizeof(variable)) #prints 28
If I change integer value with string
import sys
variable = "30"
print(sys.getsizeof(variable)) #prints 51
So does it means integer object makes use of less memory than string object.
Please let me know how Python makes use of memory.
Upvotes: 4
Views: 4829
Reputation: 164
Yes integer object use 28 byte of memory while string object is getting bigger size of memory.
Upvotes: 5