title: Lifetime of default function arguments in python
body: <p>I just started learning python, just got struck by the default argument concept.</p>
  
  <p>It is mentioned in python doc that the default argument value of a function is computed only once when the <code>def</code> statement is encountered. This makes a large difference between values of immutable and mutable default function arguments.</p>
  
  <pre><code>&gt;&gt;&gt; def func(a,L=[]):
        L.append(a)
        return L
  &gt;&gt;&gt; print(func(1))
  [1]
  &gt;&gt;&gt; print(func(2))
  [1, 2]
  </code></pre>
  
  <p>here the mutable function argument L retains the last assigned value (since the default value is calculated not during function call as like in C)</p>
  
  <p><strong>is the lifetime of the default argument's value in python is lifetime of the program (like static variables in C) ?</strong></p>
  
  <p><em><strong>Edit :</em></strong></p>
  
  <pre><code>&gt;&gt;&gt; Lt = ['a','b']
  &gt;&gt;&gt; print(func(3,Lt))
  ['a', 'b', 3]
  &gt;&gt;&gt; print(func(4))
  [1, 2, 4]
  </code></pre>
  
  <p>here during the function call <code>func(3,Lt)</code> the default value of <code>L</code> is preserved, it is not overwritten by <code>Lt</code>.</p>
  
  <p>so is default argument have two memory? one for actual default value (with program scope) and other for when an object is passed to it (with scope of function call)?</p>