Python 字典(Dictionary) update() 函数把字典dict2的键/值对更新到dict里。

dict2 – 添加到指定字典dict里的字典。

#!/usr/bin/python

dict = {'Name': 'Zara', 'Age': 7}
dict2 = {'Sex': 'female' }

dict.update(dict2)
print "Value : %s" %  dict
以上实例输出结果为:

Value : {'Age': 7, 'Name': 'Zara', 'Sex': 'female'}
a = {1:2,2:2}
b = {1:1,3:3}
b.update(a)
print(b)

在这里插入图片描述

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐