PEP 584 – Add + and – operators to the built-in dict class
An approximate pure-Python implementation of the merge operator will be: def __add__(self, other): if isinstance(other, dict): new = type(self)() # May be a subclass of dict. new.update(self) new.update(other) return new return NotImplemented def __radd__(self, other): if isinstance(other, dict): new = type(other)() new.update(other) new.update(self) return new return NotImplemented Note that the result type will be the type of the left operand; in the event of matching keys, the winner is the right operand. An approximate pure-Python implementation of the difference operator will be: def __sub__(self, other): if isinstance(other, dict): new = type(self)() for k in self: if k not in other: new[k] = self[k] return new return NotImplemented def __rsub__(self, other): if isinstance(other, dict): new = type(other)() for k in other: if k not in self: new[k] = other[k] return new return NotImplemented Augmented assignment will operate on equivalent terms to .
Source: www.python.org