Memory allocation in python
<p>I create a list with three elements named l after that I copy all the content of the list into the list y. But when I print the address of them in the memory I don't understand why this is not the same address. Why y is not a reference of l, and if I want that y will be a reference of l so that they will have the same address. How can I do this ?</p>

<p>This is my code</p>

<pre><code>l = [8,12,3]
y = l[:]

print l
print y

print id(l)
print id(y)
</code></pre>

<p>Display on the screeen :</p>

<pre><code>[8, 12, 3]
[8, 12, 3]
40894592 
40837072
</code></pre>

<p><code>[:]</code> copies the content of <code>l</code> to a new list <code>y</code>, so they need to be in different addresses. To make <code>y</code> a reference of <code>l</code>, simply write</p>

<pre><code>y = l
</code></pre>

python memory