您要使用的
dict.update方法:
d1 = {'UID': 'A12B4', 'name': 'John', 'email': '[email protected]'}d2 = {'UID': 'A12B4', 'other_thing': 'cats'}d1.update(d2)
输出:
{'email': '[email protected]', 'other_thing': 'cats', 'UID': 'A12B4', 'name': 'John'}
从文档中:
使用其他键/值对更新字典,覆盖现有键。不返回。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)