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中的键值

posted @ 2011-09-21 16:58  SophiaTang  阅读(1364)  评论(0编辑  收藏  举报