python3.9 字典合并 (|) 与更新 (|=) 运算符

python3.9新增加了合并 (|) 与更新 (|=) 运算符,加入内置的 dict 类。

它们为现有的 dict.update 和 {**d1, **d2} 字典合并方法提供了补充。

>>> x = {"key1": "value1 from x", "key2": "value2 from x"}
>>> y = {"key2": "value2 from y", "key3": "value3 from y"}
>>> x | y
{'key1': 'value1 from x', 'key2': 'value2 from y', 'key3': 'value3 from y'}
>>> y | x
{'key2': 'value2 from x', 'key3': 'value3 from y', 'key1': 'value1 from x'}