Python: Default Parameters Values
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1132941/least-astonishment-in-python-the-mutable-default-argument">&ldquo;Least Astonishment&rdquo; in Python: The Mutable Default Argument</a>  </p>
</blockquote>



<p>I was reading <a href="http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#other-languages-have-variables" rel="nofollow">this</a> link and got confused with Python's default parameters values. here is the code snippet:</p>

<pre><code>def bad_append(new_item, a_list=[]):
    a_list.append(new_item)
    return a_list

&gt;&gt;&gt; print bad_append('one')
['one']
&gt;&gt;&gt; print bad_append('two')
['one', 'two']
</code></pre>

<p>In the second print statement why is 'one' persisted? Shouldn't the list ['one'] be out of scope after the first print statement?</p>

<p>Essentially I am confused about the scope of variable between the function calls.</p>
