Mutable types as function parameter default value

… each default value is evaluated when the function is defined—i.e., usually when the module is loaded—and the default values become attributes of the function object. So if a default value is a mutable object, and you change it, the change will affect every future call of the function.

Fluent Python, 2nd Edition, Luciano Ramalho

Leave a comment