>> 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 ==================================
_______________________________________________ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig