python memorize default parameter value or not
<p>From this blog, it seems Python memorize default parameter value during each function call.</p>

<p><a href="http://effbot.org/zone/default-values.htm" rel="nofollow">http://effbot.org/zone/default-values.htm</a></p>

<p>But I tested and it seems not? For example, the 2nd function call does not print value of x, y is still False other than memorized value?</p>

<pre><code>def foo(x, y=False):
    if y:
        print x

if __name__ == "__main__":
    foo(100, True) # print
    foo(300) # not print
</code></pre>

<p>regards,
Lin</p>

<p>Python doesn't "memorize" anything during each call.  It saves one <em>default</em> value once, when the function is defined.  In your example, when <code>foo</code> is defined, <code>y</code> has a default value of False.  In your first call, you pass in a different value for <code>y</code>.  That value is used for that call, but doesn't affect the default.  On your second call, you don't explicitly pass anything for <code>y</code>, so the default is used.</p>

<p>The default value doesn't mean "whatever value was used most recently".  It's a default value.</p>

python python-2.7