Python 字典(Dictionary) update() 函数把字典dict2的键/值对更新到dict里。
dict.update(dict2)
dict = {‘Name‘: ‘Zara‘, ‘Age‘: 7}
dict2 = {‘Sex‘: ‘female‘ }
dict.update(dict2)
print("Value : %s" %  dict)
#Value : {‘Name‘: ‘Zara‘, ‘Age‘: 7, ‘Sex‘: ‘female‘}
用 update 更新字典 a,会有两种情况:
a = {1: 2, 2: 2}
b = {1: 1, 3: 3}
a.update(b)
print(a)
#{1: 1, 2: 2, 3: 3}
原文:https://www.cnblogs.com/cgmcoding/p/14428683.html