1. 字典的合并:
(1). 使用update()方法:
a = {‘Name‘:‘Bob‘, ‘Age‘:‘7‘} b = {‘Sex‘:‘female‘} c = {} c.update(a) c.update(b) print(c)
(2). 使用dict(d1, **d2)方法:
a = {‘Name‘:‘Bob‘, ‘Age‘:‘7‘} b = {‘Sex‘:‘female‘} c = dict(a, **b) print(c)
(3). 常规处理:
a = {‘Name‘:‘Bob‘, ‘Age‘:‘7‘} b = {‘Sex‘:‘female‘} c = {} for k, v in a.items(): c[k] = v for k, v in b.items(): c[k] = v print(c)
原文:https://www.cnblogs.com/dx-Dark/p/9072267.html