title: Array inside an array in Python
body: <p>This is not really a question about an error. Rather, a clarification on how things work.</p>
  
  <p>I am putting an element(0 for example) inside an array which is also inside an array. Doing it iteratively, the code looks like this:</p>
  
  <pre><code>arr = [[0 for x in range(2)] for x in range(2)]
  </code></pre>
  
  <p>Recursively,</p>
  
  <pre><code>def zero(array,n,i):
  if i &gt;= n:
      return array
  else:
      array[i].append(0)
      return zero(array,n,i+1)
  
  arr = [[]] * 2
  print zero(arr,2,0)
  </code></pre>
  
  <p>They would both have an output like this:
          [[0,0],[0,0]]</p>
  
  <p>I did not get the  process that the recursion underwent(I just accidentally made that code through trial and error.). </p>
  
  <p>What I did not get was since I am appending zero in the first array(with index zero) inside the bigger array, shouldn't '0' be appended only in the first array and not on the second array? But that is not the case, '0' was appended to both array. And when it returns the function, instead of appending '0' to the second array, it was appended to both array again.</p>
  
  <p>I tried to trace it but I really don't understand how it happened. Thank you for the response.</p>