"Hmmmm, that's strange... we altered only one list but both were changed in the end! Why would that happen? Welp, the two reasons behind that are $1)$ what a variable actually <b>is</b>; and, $2)$ what the $=$ operator actually does. In short, variables are just links to the spatial location where objects are stored. By reassigning the value of a variable, you're just changing this link.<br><br>So, first, when you create 2 lists, <b><code>var1 = [1, 2, 3]</code></b> and <b><code>var2 = [555, 777, 888]</code></b>, you create two different objects: <b><code>var1</code></b>, a variable referring to the list <b><code>[1, 2, 3]</code></b>; and <b><code>var2</code></b>, a variable referring to the list <b><code>[555, 777, 888]</code></b>. Then, with the line <b><code>var1 = var2</code></b> you don't actually change the content of <b><code>var1</code></b> — you just make it refer to the list <b><code>[555, 777, 888]</code></b>! Thus, by changing one element of <b><code>var2</code></b> you will be able to see changes in <b><code>var1</code></b> as well since they both refer to the same object in memory! Here's a sketch of the described situation:\n",
0 commit comments