Python 101 : Mutables a default parameters to functions.


 When we pass a mutable default argument to a function - here the __init__() funtion - , that accepts a list, changing the default mutable argument will also modify the original object - see output -:


We could avoid that issue by creating a new list using our "original" object as we can see below:

Comments

Leave as a comment:

Archive