Skip to content
Advertisement

Tag: overwrite

Python: Reassigning Object to Class with No Constructor Does Not Overwrite Dictionary Field

I’m using Python 3.9.1 and am confused how Python’s default constructor works. I have the below class with a Dictionary field and no Constructor. When I populate its Dictionary and then reassign my object to a new instance, the dictionary retains its existing value (this also happens for List fields): However, when I add a constructor, it works as expected:

Advertisement