title: Do I need to use list() to append a list into another list in Python?
body: <p>I am trying to append small (<strong>num</strong>) lists to a final list (<strong>lst</strong>).
  The small lists are modified in a loop and at each modification they are appended to the final list.
  But the result is strange and I did not like the solution.
  Here is the code.</p>
  
  <pre><code>n   = 3
  num = []
  lst = []
  
  for i in range(n) :
      num.append(0)
  
  lst.append(num)
  
  for j in range(n-1) :
      for i in range(n) :
          num[i] += 1
          lst.append(num)
  
  for each in lst :
      print each
  </code></pre>
  
  <p>The result of this code is:</p>
  
  <pre><code>[2, 2, 2]
  [2, 2, 2]
  [2, 2, 2]
  [2, 2, 2]
  [2, 2, 2]
  [2, 2, 2]
  [2, 2, 2]
  </code></pre>
  
  <p>However, if instead of using <code>lst.append(num)</code>, I use <code>lst.append(list(num))</code>, I get the expected result:</p>
  
  <pre><code>[0, 0, 0]
  [1, 0, 0]
  [1, 1, 0]
  [1, 1, 1]
  [2, 1, 1]
  [2, 2, 1]
  [2, 2, 2]
  </code></pre>
  
  <p>Is this really the correct way for appending values of a list to another list?</p>
  
  <p>UPDATE:
  I see that when I do <code>lst.append(num)</code> this does not mean that the values of num are appended to <strong>lst</strong>. It is a reference and because I change the content of <strong>num</strong>, in the end, all entries of my list <strong>lst</strong> will reference to the final <strong>num</strong>. However, if I do this:</p>
  
  <pre><code>lst = []
  
  for i in range(3) :
      num = i
      lst.append(num)
  
  for each in lst :
      print each
  </code></pre>
  
  <p>I get what is expected, i.e., a list <strong>lst</strong> with the values [0, 1 , 2]. And in this case, <strong>num</strong> is changed at every iteration and its final value is <strong>num</strong>=2.</p>