Heim  >  Artikel  >  Backend-Entwicklung  >  在Python中操作字典之update()方法的使用

在Python中操作字典之update()方法的使用

WBOY
WBOYOriginal
2016-06-06 11:17:221192Durchsuche

 update()方法添加键 - 值对到字典dict2。此函数不返回任何值。
语法

以下是update()方法的语法:

dict.update(dict2)

参数

  •     dict2 -- 这是被添加dict到的词典

返回值

此方法不返回任何值
例子

下面的例子显示了update()方法的使用

#!/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'}

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn