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. Java实现的上传并压缩图片功能【可等比例压缩或原尺寸压缩】

    本文实例讲述了Java实现的上传并压缩图片功能.分享给大家供大家参考,具体如下: 先看效果: 原图:1.33M 处理后:27.4kb 关键代码: package codeGenerate.util; ...

  2. 通过ssh-copy-id免密码连接Linux主机

    Login Raspberry Pi without passcode via ssh-copy-id Generate public key $ ssh-keygen -t rsa Upload p ...

  3. 用Java在excel单元格中设置超链接

    (一)问题引入 有时候我们在导入数据到excel中时可能要给某个文件或图片设置超链接,例如链接到外网或者是本地的某个目录.我们可以通过Java代码来实现,借助POI库. (二)解决方案 下面直接给出参 ...

  4. markdwon编辑公式入门

    上标与下标   上标和下标分别使用^ 与_ ,例如\(x_i^2\)表示的是:.   默认情况下,上.下标符号仅仅对下一个组起作用.一个组即单个字符或者使用{..} 包裹起来的内容.如果使用\(10^ ...

  5. Trie树相关博客

    1. c++代码实现,包含删除操作:https://www.cnblogs.com/luxiaoxun/archive/2012/09/03/2668611.html 2. 一种典型实现及简单分析:h ...

  6. Struts2学习-struts执行过程简述

    1.web.xml <web-app> <filter> <filter-name>struts2</filter-name> <filter-c ...

  7. Application Characteristics Of LED Keychain

    LED keychains are essential camping and travel accessories. Very useful as a light source. There are ...

  8. 使用VSCode创建简单的Razor Webapp--1.入门

    1.下载vscode,安装dotnet core sdk 在cmd中使用命令dotnet --version可以查看当前安装的版本 2.打开vscode,设置语言和扩展 在最左边的工具栏,点击最下面的 ...

  9. AntDesign(React)学习-14 使用UMI提供的antd模板

    1.UMI提供了可视化antd模板,可以直接添加到项目中修改用 比如将个人中心添加到项目中 2.选择个人中心,确定 3.成功 4.打开项目 5.Route文件也自动添加 根路由有exact:true后 ...

  10. 为什么 K8s 在阿里能成功(转)

    为什么 K8s 在阿里能成功?| 问底中国 IT 技术演进   作者:曾凡松 阿里云云原生应用平台高级技术专家张振 阿里云云原生应用平台高级技术专家 导读:本文描述了阿里巴巴在容器管理领域的技术演进历 ...