Late-binding of function defaults (was Re: What is a function parameter =[] for?)
Marko Rauhamaa
marko at pacujo.net
Thu Nov 19 15:57:10 EST 2015
Laura Creighton <lac at openend.se>:
> My experience says that the people who are confused want lists to
> behave like tuples. period. i.e. they don't want lists to be mutable.
I think it's simpler than that. When you have:
def f(x=[]):
y = []
the first [] is evaluated when "def" is executed, while the latter [] is
evaluated whenever "f" is executed. It's easy to be confused.
Marko
More information about the Python-list
mailing list