Python 3 – 字典 update()方法 |
您所在的位置:网站首页 › 字典update方法 › Python 3 – 字典 update()方法 |
Python 3 – 字典 update()方法
描述
方法 update() 将字典dict2的键值对添加到dict中。这个函数不返回任何值。 语法以下是 update() 方法的语法− dict.update(dict2) 参数dict2 − 这是要添加到dict中的字典。 返回值这个方法不返回任何值。 示例以下示例展示了update()方法的用法。 #!/usr/bin/python3 dict = {'Name': 'Zara', 'Age': 7} dict2 = {'Sex': 'female' } dict.update(dict2) print ("updated dict : ", dict) 结果运行以上程序,将产生以下结果− updated dict : {'Sex': 'female', 'Age': 7, 'Name': 'Zara'} |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |