[Tutor] Surprising behaviour of optional argument

Jose Amoreira ljmamoreira at gmail.com
Fri Jul 18 00:00:33 CEST 2014


Hi
On 07/17/2014 06:34 PM, Danny Yoo wrote:
>

> 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!
>

Aha, the object that stores the default value for the optional argument 
is created at the time of the execution of the function definition and 
mutable objects do mutate, so that's that. It makes a lot of sense.
Thanks, Danny


More information about the Tutor mailing list