update() 函数把字典dict2的键/值对更新到dict里。如果后面的键有重复的会覆盖前面的
语法
dict.update(dict2)

dict = {'Name': 'Zara', 'Age': 7}
dict2 = {'Sex': 'female','Name':'zhangsan'}
dict.update(dict2)
print "Value : %s" % dict

结果:

root@tao:/home/tao# python
Python 2.7. (default, Nov , ::)
[GCC 9.2. ] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> dict = {'Name': 'Zara', 'Age': }
>>> dict2 = {'Sex': 'female','Name':'zhangsan'}
>>> dict.update(dict2)
>>> print "Value : %s" % dict
Value : {'Age': , 'Name': 'zhangsan', 'Sex': 'female'}
>>>

php中类似的语法是array_merge

array_merge() 将一个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面。返回作为结果的数组。
如果输入的数组中有相同的字符串键名,则该键名后面的值将覆盖前一个值。然而,如果数组包含数字键名,后面的值将不会覆盖原来的值,而是附加到后面。
如果只给了一个数组并且该数组是数字索引的,则键名会以连续方式重新索引。

<?php
$array1 = array("color" => "red", , );
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", );
$result = array_merge($array1, $array2);
print_r($result);
?>
以上例程会输出: Array
(
[color] => green
[] =>
[] =>
[] => a
[] => b
[shape] => trapezoid
[] =>
)

[python]Python 字典(Dictionary) update()方法的更多相关文章

  1. Python字典(Dictionary)update()方法

    原文连接:https://www.runoob.com/python/att-dictionary-update.html Python字典(dictionary)update()函数把字典dict2 ...

  2. Python 字典(Dictionary) update()方法

    refer to: http://www.runoob.com/python/att-dictionary-update.html

  3. Python 字典(Dictionary) clear()方法

    Python 字典(Dictionary) clear()方法 描述 Python 字典(Dictionary) clear() 函数用于删除字典内所有元素.高佣联盟 www.cgewang.com ...

  4. Python 字典(Dictionary) type()方法

    Python 字典(Dictionary) type()方法 描述 Python 字典(Dictionary) type() 函数返回输入的变量类型,如果变量是字典就返回字典类型.高佣联盟 www.c ...

  5. Python 字典(Dictionary) str()方法

    Python 字典(Dictionary) str()方法 描述 Python 字典(Dictionary) str() 函数将值转化为适于人阅读的形式,以可打印的字符串表示.高佣联盟 www.cge ...

  6. Python 字典(Dictionary) len()方法

    Python 字典(Dictionary) len()方法 描述 Python 字典(Dictionary) len() 函数计算字典元素个数,即键的总数.高佣联盟 www.cgewang.com 语 ...

  7. Python 字典(Dictionary) cmp()方法

    Python 字典(Dictionary) cmp()方法 描述 Python 字典的 cmp() 函数用于比较两个字典元素.高佣联盟 www.cgewang.com 语法 cmp()方法语法: cm ...

  8. Python 字典(Dictionary) get()方法

    描述 Python 字典(Dictionary) get() 函数返回指定键的值,如果值不在字典中返回默认值. 语法 get()方法语法: dict.get(key, default=None) 参数 ...

  9. Python 字典(Dictionary) setdefault()方法

    描述 Python 字典(Dictionary) setdefault() 函数和get()方法类似, 如果键不已经存在于字典中,将会添加键并将值设为默认值. 语法 setdefault()方法语法: ...

随机推荐

  1. Github+Hexo一站式部署个人博客(原创)

    写在前面 注:博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 本文源链接:https://www.cnblogs.com/chloneda/p/hexo.ht ...

  2. 【Unity|C#】基础篇(17)——字符串处理(String/StringBuilder)

    [学习资料] <C#图解教程>(第25章):https://www.cnblogs.com/moonache/p/7687551.html 电子书下载:https://pan.baidu. ...

  3. 树莓派4B遇到的坑

    由于大创需要用到机器学习这些东西,入手了一个树莓派4B(新手没弄过,直接上手最新版果然是有坑的),大佬勿喷

  4. 【你不知道的javaScript 上卷 笔记4】javaScript 中闭包的一些运用

    什么是闭包 闭包是javaScript语言的一种特性,在 javaScript 中以函数作为承接单元.当函数可以记住并访问所在的词法作用域时,就产生了闭包,即使函数是在当前词法作用域之外执行. fun ...

  5. 【Python】表白程序

     程序链接:https://www.lanzous.com/i8xj5mh # 打包操作 # 安装pyinstaller # cmd输入 pip install pyinstaller # shift ...

  6. Python之路Day08

    文件操作 open() -- 打开 open通过Python控制操作系统打开文件 f=open('文件路径',mode='r',encoding='utf-8') mode -- 不写就默认是r f ...

  7. [BOI2003] Gem - 树形dp

    结论 不同颜色数不会超过 \(O(\log n)\) 然后就是很简单的树形dp了 顺便复习一下树形dp怎么写 #include <bits/stdc++.h> using namespac ...

  8. BFS-八数码问题与状态图搜索

    在一个3*3的棋盘上放置编号为1~8的八个方块,每个占一格,另外还有一个空格.与空格相邻的数字方块可以移动到空格里.任务1:指定的初始棋局和目标棋局,计算出最少的移动步数:任务2:数出数码的移动序列. ...

  9. 二、vim的保存文件和退出命令

    vim的保存文件和退出命令   命令 简单说明 :w 保存编辑后的文件内容,但不退出vim编辑器.这个命令的作用是把内存缓冲区中的数据写到启动vim时指定的文件中. :w! 强制写文件,即强制覆盖原有 ...

  10. wpf 移动动画

    private void moveTo(Point deskPoint, Control ell, double space) //deskPoint: 控件要移动到的位置 , ell :你要移动的空 ...