title: Python: why appending to a list results in same values
body: <p>This is my code:</p>
  
  <pre><code>a = []
  res = []
  for i in range(0, 3):
      a.append(i)
      res.append(a)
  print(res)
  </code></pre>
  
  <p>The result is:</p>
  
  <pre><code>[[0, 1, 2], [0, 1, 2], [0, 1, 2]] 
  </code></pre>
  
  <p>But I want the result to be:</p>
  
  <pre><code>[[0], [0, 1], [0, 1, 2]]
  </code></pre>
  
  <p>I know the solution is using the shallow copy: <code>res.append(a[:])</code>. But can somebody tell me why?</p>