I have just read an article: The 10 Most Common Mistakes That Python Developers Make. The problem #1 still puzzled me a lot. I will describe my problem with the codes below.
>>>def foo(bar=[]):
... bar.append("baz")
... return bar
>>> foo()
["baz"]
>>> foo()
["baz", "baz"]
It not works, the answer in the article says list is an multable type and the default value changes during the call.But when I try this one
def foo(bar=[]):
if bar == []:bar=[]
...
it works, so what makes the difference?