title: UnboundLocalError while using += but not append list
body: <p>I do not quite understand the difference between the following two similar codes:</p>
  
  <pre><code>def y(x):
      temp=[]
      def z(j):
          temp.append(j)
      z(1)
      return temp
  </code></pre>
  
  <p>calling <code>y(2)</code> returns <code>[1]</code></p>
  
  <pre><code>def y(x):
      temp=[]
      def z(j):
          temp+=[j]
      z(1)
      return temp
  </code></pre>
  
  <p>calling <code>y(2)</code> returns <code>UnboundLocalError: local variable 'temp' referenced before assignment</code>. Why <code>+</code> operator generates the error? Thanks</p>