In this particular case, this is because list are mutable.
As a result, their use in the global namespace or even passing through a function means that they will be changed, because Python contains a reference to the mutable object, and not a copy of it.
If you try to do the same with tuple , this will not work, as they are immutable.
A way to avoid this is to provide a copy of the function list, not the list itself:
func2(list[:])
At the same time, you can do this with the default arguments, where you can specify the default argument as [] , and if you then .append() something to it, this default argument permanently holds this element inside it for all future calls (unless you delete them in any way).
source share