title: Python: deepcopy(list) vs new_list = old_list[:]
body: <p>I'm doing exercise #9 from <a href="http://openbookproject.net/thinkcs/python/english2e/ch09.html" rel="noreferrer">http://openbookproject.net/thinkcs/python/english2e/ch09.html</a> and have ran into something that doesn't make sense.</p>
  
  <p>The exercise suggests using <code>copy.deepcopy()</code> to make my task easier but I don't see how it could.</p>
  
  <pre><code>def add_row(matrix):
      """
          &gt;&gt;&gt; m = [[0, 0], [0, 0]]
          &gt;&gt;&gt; add_row(m)
          [[0, 0], [0, 0], [0, 0]]
          &gt;&gt;&gt; n = [[3, 2, 5], [1, 4, 7]]
          &gt;&gt;&gt; add_row(n)
          [[3, 2, 5], [1, 4, 7], [0, 0, 0]]
          &gt;&gt;&gt; n
          [[3, 2, 5], [1, 4, 7]]
      """
  
      import copy
      # final = copy.deepcopy(matrix)  # first way
      final = matrix[:]                # second way
      li = []
      for i in range(len(matrix[0])):
          li.append(0)
      # return final.append(li)  # why doesn't this work?
      final.append(li)            # but this does
      return final
  </code></pre>
  
  <p>I'm confused why the book suggests using <code>deepcopy()</code> when a simple <code>list[:]</code> copies it. Am I using it wrong? Is my function completely out of wack?</p>
  
  <p>I also have some confusion returning values. the question is documents in the code above.</p>
  
  <p>TIA</p>