Avoiding Mutable Default Arguments in Python
See also: The Hitchhiker’s Guide to Python
IDE’s like PyCharm will complain when this is attempted, in which you’ll see messages like the following:
Default argument value is mutable...
Inspection info: This inspection detects when a mutable value as list or dictionary is detected in a default value for an argument. Default argument values are `evaluated only once at function definition time`, which means that modifying the default value of the argument will affect all subsequent calls of the function.
Posted in python