def _del_ (self)acc self accountref(get account if accunregister if still exists acc unregister(selfdef update(self)print("balance is % fself accountref(balancedef close(self)print("account no longer in use"example setup account('dave', a_ob accountobserver(ain this examplea weak reference accountref is created to access the underlying accountyou call it like function this either returns the account or none if it' no longer around with this modificationthere is no longer reference cycle if the account object is destroyedits _del_ method runs and observers receive notification the gc module also works properly more information about the weakref module can be found in "python runtime services object representation and attribute binding internallyinstances are implemented using dictionary that' accessible as the instance' __dict__ attribute this dictionary contains the data that' unique to each instance here' an examplea account('guido' _dict_ {'balance' 'name''guido'new attributes can be added to an instance at any timelike thisa number add attribute 'numberto _dict_ modifications to an instance are always reflected in the local _dict_ attribute likewiseif you make modifications to _dict_ directlythose modifications are reflected in the attributes instances are linked back to their class by special attribute _class_ the class itself is also just thin layer over dictionary which can be found in its own _dict_ attribute the class dictionary is where you find the methods for examplea _class_ account _dict_ keys([' _dict_ '' _module_ ''inquiry''deposit''withdraw'' _del_ ''num_accounts'' _weakref_ '' _doc_ '' _init_ 'finallyclasses are linked to their base classes in special attribute _bases_ _which is tuple of the base classes this underlying structure is the basis for all of the operations that getsetand delete the attributes of objects whenever an attribute is set using obj name valuethe special method obj _setattr_ ("name"valueis invoked if an attribute is deleted using del obj namethe special method obj _delattr_ ("name"is invoked the default behavior of these methods is to modify or remove values from the local _dict_ of obj unless the requested attribute happens to correspond to property or descriptor in lib fl ff