Arunkrishna
Arunkrishna

Reputation: 71

Python memory usage for integer and string

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

Answers (1)

Vahid Bahramian
Vahid Bahramian

Reputation: 164

Yes integer object use 28 byte of memory while string object is getting bigger size of memory.

Upvotes: 5

Related Questions