Python字典update()
方法用于将dict2
的键值对添加到dict
。此方法不返回任何内容。
语法
以下是update()
方法的语法 -
dict.update(dict2)
参数
- dict2 - 这是要添加到字典
dict
中的字典。
返回值
- 此方法不返回任何值。
示例
以下示例显示update()
方法的用法 -
#!/usr/bin/python3
dict = {'Name': 'Maxsu', 'Age': 7}
dict2 = {'Sex': 'female' }
dict.update(dict2)
print ("updated dict : ", dict)
当运行上面的程序,它产生以下结果 -
updated dict : {'Sex': 'female', 'Age': 7, 'Name': 'Maxsu'}
上一篇:
Python字典
下一篇:
Python日期和时间