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>Assignment in Python is by reference - it creates a new reference, or alias for an object, not copies the object - and since event <em>int</em> is an object in Python - at least (in my version - up to 256), this rule mostly works works.</p>

<p>The following example wit function <em>id</em> - which shows object reference - illustrates the point</p>

<pre><code>In [37]: a = range(1, 6)

In [38]: b = range(1, 6)

In [39]: id(1)
Out[39]: 4298160472

In [40]: id(a[0])
Out[40]: 4298160472

In [41]: id(a)
Out[41]: 4376534696

In [42]: id(b)
Out[42]: 4378531744

In [44]: c = a

In [45]: id(c)
Out[45]: 4376534696
</code></pre>

<p>However, this will not work on floats - which is logical, since quantity of floats, and integers is infinite</p>

<pre><code>In [49]: a = .1

In [50]: b = .1

In [51]: id(a)
Out[51]: 4298708040

In [52]: id(b)
Out[52]: 4303248152
</code></pre>

<p>As you may see, new object is created for each new float, though value is the same</p>

python arrays python-2.7