python两个dict相加
python两个dict相加
>>> a = {'1':'2'}
>>> b = {'3':'4'}
>>> a+b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'dict' and 'dict'
>>> a.update(b)
>>> a
{'1': '2', '3': '4'}
>>>
该方法把b的元素加入到a中去,键字重复时会覆盖a中的键值