title: Python function argument passed "between" calls
body: <p>This is an example from the book "Introducing Python" by Bill Lubanovic illustrating some basics of user-defined functions:</p>
  
  <pre><code>def buggy(arg, result = []):
      result.append(arg)
      print(result)
  
  buggy('a')
  buggy('b')
  </code></pre>
  
  <p>The "expected" output is a list comprised only of <code>arg</code> in both cases, but after the second call one gets the list <code>['a', 'b']</code>, suggesting that <code>result</code> is being carried over to the next call.  Maybe this isn't surprising, but when I try to print this object it doesn't exist:</p>
  
  <pre><code>In [53]: def buggy(arg, result = []):
     ....:     result.append(arg)
     ....:     print(result)
     ....:     
  
  In [54]: buggy('a')
  ['a']
  
  In [55]: result
  ---------------------------------------------------------------------------
  NameError                                 Traceback (most recent call last)
  &lt;ipython-input-55-a5b1e83cd027&gt; in &lt;module&gt;()
  ----&gt; 1 result
  
  NameError: name 'result' is not defined
  
  In [56]: buggy('b')
  ['a', 'b']
  </code></pre>
  
  <p>What exactly is going on here?  Is the issue that <code>result</code> doesn't exist outside the function, but somehow the second call of <code>buggy</code> "knows" about the <code>result</code> that was created by the first call and decides to use it as an argument?  The author doesn't really explain what's happening.</p>