In the past few months I’ve been helping some people who are new to Python to get to know the language. I found that there are some pitfalls that almost everyone meet when they’re new to the language, so I decided to share my advice with you. Each part of this series will focus on a different common mistake, describe what causes it and offer a solution.
They are not quite equivalent. The first explicitly checks the identity of numbers; the second checks its truthiness. The difference often matters: for example, using a logical or in the second definition of foo() would mutate the list supplied only if it was not empty.
I would call this a wart in Python's design. Amir addressed this point somewhat. For mutable values, each call of a function should get a copy of the default value. One possible counterpoint is that in some way the existing semantic could be useful, but I think that's a weak argument. I don't see any use for this behavior that can't be addressed MUCH more clearly with a closure, an instance variable or a class variable.