菜鸟IT的博客 >> Python
合并2个字典 | 合并的时候,如果后面的字典拥有和前面的字典一样的“键”,那么合并后的字典会以后面的“键”的值为准
dictionary_one = {"a": 1, "b": 2}
dictionary_two = {"c": 3, "d": 4}
merged = {**dictionary_one, **dictionary_two}
print(merged) # {'a': 1, 'b': 2, 'c': 3, 'd': 4}
# ——————————————————————
dictionary_one = {"a": 1, "b": 2,"c":5}
dictionary_two = {"c": 3, "d": 4}
merged = {**dictionary_one, **dictionary_two}
print(merged) # {'a': 1, 'b': 2, 'c': 3, 'd': 4}
菜鸟IT博客[2022.10.23-10:47] 访问:393
※※相关信息专题※※
§【python技巧】