The Surprising Case Of Mutable Default Arguments
Too Long; Didn't Read
A Python function takes in an argument which also has a default value assigned to it. Default arguments are bind to the function as soon as the function is defined. But default arguments are mutable so we get the same results instead of a new list being created on each function call. And the same list is being mutated/modified again and again. We have a single list and the default argument always modifies the same thing. The default argument is a mutable list which is mutable and that's what is happening here.