I put a dict as the default value for an optional argument to a Python function, and pylint (using Sublime package) told me it was dangerous. Can someone explain why this is the case? And is a better alternative to use None instead?
143
votes
The problem with pasing empty list as a default argument is that it will be shared between all invocations of the function -- see the "important warning" in docs.python.org/3/tutorial/…
- hamed
2 Answers
184
votes