<font face="tahoma,sans-serif"><div>>> def f(n, history = []):</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> history.append(n)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> return history</div>
<div><br></div><div>>>> f(1)</div><div>[1]</div><div>>>> f(2)</div><div>[1, 2]</div><div>>>> f(3)</div><div>[1, 2, 3]</div><div>>>> f(2)</div><div>[1, 2, 3, 2]</div><div>>>> f(1)</div>
<div>[1, 2, 3, 2, 1]</div><div>>>> f(1,[])</div><div>[1]</div><div><br></div><div>A student wrote me wondering why his function wouldn't 'clear' after being called. He meant to create an empty list and ended up with something like this.</div>
<div><br></div><div>What's a good way to explain what's going on?</div><div><br></div><div>- Michel</div><div><br></div><div><br></div></font><br>-- <br><div>==================================<br>"What I cannot create, I do not understand."</div>
<div><br></div><div>- Richard Feynman</div>==================================<br>"Computer science is the new mathematics."<div><br></div><div>- Dr. Christos Papadimitriou<br>==================================<br>
</div><br>