[Tutor] How memory works in Python
Deepak Dixit
deepakdixit0001 at gmail.com
Tue Jan 7 09:44:45 EST 2020
Hi Team,
I was thinking on the memory management in Python but little confused here
because when I assign same value of type number and string to different
variable, it points to same memory but when I do it for list or tuple it
points to different memory locations.
Here is the code and the output:
# test.py
x1 = 10
y1 = 10
x2 = "Hello"
y2 = "Hello"
x3 = [10]
y3 = [10]
x4 = (10,)
y4 = (10,)
print id(x1) == id(y1)
print id(x2) == id(y2)
print id(x3) == id(y3)
print id(x4) == id(y4)
deepak at Deepak-PC:~$ python test.py
True
True
False
False
Can you help me to understand how it works?
--
*With Regards,*
*Deepak Kumar Dixit*
More information about the Tutor
mailing list