Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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]


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: