Hacker News new | ask | show | jobs
by travisjungroth 1057 days ago
When you set an object as a default that object is the default for all calls to that function/method. This also holds true if you create the object, like that empty list. So in this case, every call that uses the default argument is using the same list.

    def listify(item, li=[]):
        li.append(item)
        return li

    listify(1) # [1]
    listify(2) # [1, 2]