[Tutor] Memory management in Python

Mohamed Ben Mosbah benmosbahmohamed at gmail.com
Wed Nov 26 13:57:52 CET 2014


Hi I'm new to Python and I would like to know how he deals with memory
space.
I thought I had understood but I made a test and the results were
uncoherenent with my understanding, here is the thing:

>>> a=[1,2]
>>> l=[a,a]
>>> id(a); id(l[0]); id(l[1]);
61659528
61659528
61659528
>>> #All Have the same ID
>>> l[0]=[0,0]
>>> l
[[0, 0], [1, 2]]
>>> #Why didn't l[1] change as well?
>>> id(a); id(l[0]); id(l[1]);
61659528
61390280
61659528
>>> #How come id(l[0]) changed?
>>> a = [4,4]
>>> l
[[0, 0], [1, 2]]
>>> #Why didn't l[1] change? l[1] and a were occupying the same memory
adress!


Thank you for answering :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141126/61ece914/attachment.html>


More information about the Tutor mailing list