Variable creation process in Python
<p>Doing everything in Microsoft shell and using 2.7.12</p>

<h1>Prelude</h1>

<pre><code>a = [1,2,3,4,5]
b = [1,2,3,4,5]
c = a
</code></pre>

<h1>Actions</h1>

<pre><code>a[0] is b[0] is c[0]
True
</code></pre>

<p>Are not the three lists pointing to the same elements in the memory location? and are therefore liable to change if one is changed?</p>

<p>Part I understand:</p>

<pre><code>c[0] = 8888888
a[0]
8888888
</code></pre>

<p>Part I don't understand:</p>

<pre><code>b[0] = 9999999
a[0]
1
</code></pre>

<p><code>int</code>s are <em>immutable</em>. This means that when you reassign <code>a[0]</code>, you're not changing whatever <code>1</code> is. Rather, you're changing whatever <code>a[0]</code> holds. You don't change what it means to be <code>1</code> - you change what it means to be <code>a[0]</code>.</p>

<p>If on the other hand you did this:</p>

<pre><code>L = [1,2,3]
a = [L]
b = [L]
a.[0].append(4)
</code></pre>

<p>you'd see the change reflected in <code>b</code> as well</p>

python arrays python-2.7