[Edu-sig] this is interesting
michel paul
mpaul213 at gmail.com
Wed Jun 8 06:51:31 CEST 2011
>> def f(n, history = []):
history.append(n)
return history
>>> f(1)
[1]
>>> f(2)
[1, 2]
>>> f(3)
[1, 2, 3]
>>> f(2)
[1, 2, 3, 2]
>>> f(1)
[1, 2, 3, 2, 1]
>>> f(1,[])
[1]
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.
What's a good way to explain what's going on?
- Michel
--
==================================
"What I cannot create, I do not understand."
- Richard Feynman
==================================
"Computer science is the new mathematics."
- Dr. Christos Papadimitriou
==================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20110607/bfa6439b/attachment.html>
More information about the Edu-sig
mailing list