Files
Mastering-Python-2e-code_2/CH_04_design_patterns/T_13_dict_union.rst
T
2022-05-05 18:25:55 +02:00

23 lines
344 B
ReStructuredText

>>> a = dict(x=1, y=2)
>>> b = dict(y=1, z=2)
>>> c = a.copy()
>>> c
{'x': 1, 'y': 2}
>>> c.update(b)
>>> a
{'x': 1, 'y': 2}
>>> b
{'y': 1, 'z': 2}
>>> c
{'x': 1, 'y': 1, 'z': 2}
------------------------------------------------------------------------------
>>> a = dict(x=1, y=2)
>>> b = dict(y=1, z=2)
>>> a | b
{'x': 1, 'y': 1, 'z': 2}