Python dictionary “plus-equal” behavior
问题 I'm trying to understand the exact mechanism behind updating a python dictionary using d[key] += diff . I have some helper classes to trace magic method invocations: class sdict(dict): def __setitem__(self, *args, **kargs): print "sdict.__setitem__" return super(sdict, self).__setitem__(*args, **kargs) def __delitem__(self, *args, **kargs): print "sdict.__delitem__" return super(sdict, self).__delitem__(*args, **kargs) def __getitem__(self, *args, **kargs): print "sdict.__getitem__" return