Python 3.9 adds in the Dictionary Merge (|) & Update Operators (|=) announcement
What are the differences between the two? What -- if any -- differences are there between the update operator and dict.update?
Python 3.9 adds in the Dictionary Merge (|) & Update Operators (|=) announcement
What are the differences between the two? What -- if any -- differences are there between the update operator and dict.update?
These are like other augmented operations. |
creates a new dictionary like {**d1, **d2}
does. |=
updates an existing dictionary like .update
.
>>> d1 = {1:1, 3:3}
>>> d2 = {2:2, 3:4}
>>>
>>> d3 = d1 | d2
>>> d3
{1: 1, 3: 4, 2: 2}
>>>
>>> d1 |= d2
>>> d1
{1: 1, 3: 4, 2: 2}