On Jul 17, 2014 10:22 AM, "Jose Amoreira" <ljmamore...@gmail.com> wrote: > > Hello > I stumbled on something I found surprising. I'm using standard python (cpython, I guess) 2.7 on openSuse 13.1. > > Consider the function > > In [2]: def f(x,y=[]): > ...: print y > ...: y.append(x) > ...: return x >
Yeah; the default value is not reevaluated between calls. It's a common gotcha. Here are a few links to read more: http://effbot.org/zone/default-values.htm http://docs.python-guide.org/en/latest/writing/gotchas/#mutable-default-arguments Good luck!
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor