r/backtickbot • • Jul 22 '21

https://np.reddit.com/r/Python/comments/opb7hm/do_not_use_mutable_objects_as_default_arguments/h65456a/

Btw using mutable objects as class attributes leaves its mark - every instance of the class will have the same object as its attribute

class Lol:
    kek = []

Lol().lol.append(None)

print(Lol().lol)
# Will be: [None]

I'm not against it, it can also be an option to use, for example, in cases when you need joint context

1 Upvotes

0 comments sorted by