Python 3 教程教程
Python3 字典 update() 方法
Python3 字典 update() 方法
Python3 字典 update() 方法
Python3 字典描述
Python 字典 update() 函数把字典参数 dict2 的 key/value(键/值) 对更新到字典 dict 里。
语法
update() 方法语法:
dict.update(dict2)
参数
- dict2 -- 添加到指定字典dict里的字典。
返回值
该方法没有任何返回值。
实例
以下实例展示了 update()函数的使用方法:
实例(Python 2.0+)
#!/usr/bin/python3
dict = {'Name': 'verydoc', 'Age': 7}
dict2 = {'Sex': 'female' }
dict.update(dict2)
print ("更新字典 dict : ", dict)
以上实例输出结果为:
更新字典 dict : {'Name': 'verydoc', 'Age': 7, 'Sex': 'female'}
Python3 字典
Python3 字典 update() 方法 |
---|
Python 3 教程
Python的3.0版本,常被称为Python 3000,或简称Py3k。相对于Python的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0在设计的时候没有考虑向下兼容。