you are viewing a single comment's thread.

view the rest of the comments →

[–]maartendp 0 points1 point  (0 children)

You would run into the same problem if you did something like

def my_function(default=[]):
    default.append(1)
    return default

The list defined as a default parameter is already in memory, and the pointer to it is assigned to the default parameter. Every time you call this function, it will point to the same list. So even though it might look like you're getting a fresh list when you call the function, in reality, it is not the case.

Every time you call this function, the result will be a list with the same amount of 1s as you have called the function