[python]Python 字典(Dictionary) update()方法
发布时间:2021-05-21 06:42:56 所属栏目:大数据 来源: https://www.jb51.cc
导读:update() 函数把字典dict2的键/值对更新到dict里。如果后面的键有重复的会覆盖前面的 语法 dict.update(dict2) dict = {'Name': 'Zara','Age': 7} dict2 = {'Sex': 'female','Name':'zhangsan'} dict.update(dict2) print "Value : %s" % dict 结果: root@t
update() 函数把字典dict2的键/值对更新到dict里。如果后面的键有重复的会覆盖前面的 dict = {'Name': 'Zara','Age': 7} 结果: root@tao:/home/tao# python Python 2.7.17 (default,Nov 7 2019,10:07:09) [GCC 9.2.1 20191008] on linux2 Type "help",1)">copyrightcredits" or license" for more information. >>> dict = {'Name': Zara',1)">Age7} >>> dict2 = {Sexfemale':zhangsan'} >>> dict.update(dict2) >>> print Value : %s" % dict Value : {7,1)">} >>> ? PHP中类似的语法是array_merge array_merge() 将一个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面。返回作为结果的数组。 <?PHP $array1 = array(color" => red2,1)">4); $array2 = array(abgreenshapetrapezoid); $result = array_merge($array1,$array2); print_r($result); ?> 以上例程会输出: Array ( [color] => green [0] => 2 [1] => 2] => a [3] => b [shape] => trapezoid [4] => ) ? (编辑:北几岛) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |