title: Optional parameters in functions and their mutable default values
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://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'm kind of confused about how optional parameters work in Python functions/methods.</p>
  
  <p>I have the following code block:</p>
  
  <pre><code>&gt;&gt;&gt; def F(a, b=[]):
  ...     b.append(a)
  ...     return b
  ...
  &gt;&gt;&gt; F(0)
  [0]
  &gt;&gt;&gt; F(1)
  [0, 1]
  &gt;&gt;&gt;
  </code></pre>
  
  <p>Why <code>F(1)</code> returns <code>[0, 1]</code> and not <code>[1]</code>?</p>
  
  <p>I mean, <strong>what is happening inside</strong>? </p>