Python recursive function result depends on previous calls when parameter has default value
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1132941/least-astonishment-in-python-the-mutable-default-argument">“Least Astonishment” in Python: The Mutable Default Argument</a>  </p>
</blockquote>



<p>I made this function:</p>

<pre><code>def test(num,v=[]):
    v.append(num)
    if num == 10:
        return v
    return test(num+1,v)
</code></pre>

<p>When I use it, the result of previous calls seems to still be there:</p>

<pre><code>&gt;&gt;&gt; test(3)
[3, 4, 5, 6, 7, 8, 9, 10]
&gt;&gt;&gt; test(3)
[3, 4, 5, 6, 7, 8, 9, 10, 3, 4, 5, 6, 7, 8, 9, 10]
&gt;&gt;&gt; test(3)
[3, 4, 5, 6, 7, 8, 9, 10, 3, 4, 5, 6, 7, 8, 9, 10, 3, 4, 5, 6, 7, 8, 9, 10]
</code></pre>

<p>If I use just <code>v</code> in the function declaration as opposed to <code>v=[]</code>, it seems to work.<br>
What am I missing? I want the function to be fresh each time I run it. I use Python 2.7.3.</p>
