python - Why can extend modify a value without a global designation?
<pre><code>&gt;&gt;&gt; x = []
&gt;&gt;&gt; y = [1,2,3]
&gt;&gt;&gt; def func1(L):
...     x+=L
... 
&gt;&gt;&gt; def func2(L):
...     x.extend(L)
... 
&gt;&gt;&gt; func1(y)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "&lt;stdin&gt;", line 2, in func1
UnboundLocalError: local variable 'x' referenced before assignment
&gt;&gt;&gt; func2(y)
&gt;&gt;&gt; x
[1, 2, 3]
</code></pre>

<p>Why can the list extend() method alter the non-global variable, but the += operator cannot? From what I understand, as long as the function doesn't assign the variable, it can read it without the global designation. but in this case the function does set the value.</p>
