英文文档:

class dict(**kwarg)

class dict(mapping, **kwarg)

class dict(iterable, **kwarg)

Return a new dictionary initialized from an optional positional argument and a possibly empty set of keyword arguments.

If no positional argument is given, an empty dictionary is created. If a positional argument is given and it is a mapping object, a dictionary is created with the same key-value pairs as the mapping object. Otherwise, the positional argument must be an iterable object. Each item in the iterable must itself be an iterable with exactly two objects. The first object of each item becomes a key in the new dictionary, and the second object the corresponding value. If a key occurs more than once, the last value for that key becomes the corresponding value in the new dictionary.

If keyword arguments are given, the keyword arguments and their values are added to the dictionary created from the positional argument. If a key being added is already present, the value from the keyword argument replaces the value from the positional argument.

说明:

  1. 字典类的构造函数。

  2. 不传入任何参数时,返回空字典。

>>> dict()
{}

  3. 可以传入键值对创建字典。

>>> dict(a = 1)
{'a': 1}
>>> dict(a = 1,b = 2)
{'b': 2, 'a': 1}

  4. 可以传入映射函数创建字典。

>>> dict(zip(['a','b'],[1,2]))
{'b': 2, 'a': 1}

  5. 可以传入可迭代对象创建字典。

>>> dict((('a',1),('b',2)))
{'b': 2, 'a': 1}

Python内置函数(15)——dict的更多相关文章

  1. Python内置函数(15)——memoryview

    英文文档: class memoryview(obj) memoryview objects allow Python code to access the internal data of an o ...

  2. Python内置函数(23)——dict

    英文文档: class dict(**kwarg) class dict(mapping, **kwarg) class dict(iterable, **kwarg) Return a new di ...

  3. python内置函数之dict()

    class dict(**kwargs) 返回一个字典.本方法用来创建一个字典对象.只能传入一个参数. >>> dict(a=1) {'a': 1} 也可以传入映射函数作为参数 &g ...

  4. 【转】python 内置函数总结(大部分)

    [转]python 内置函数总结(大部分) python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为 ...

  5. python内置函数,匿名函数

    一.匿名函数 匿名函数:为了解决那些功能很简单的需求而设计的一句话函数 def calc(n): return n**n print(calc(10)) #换成匿名函数 calc = lambda n ...

  6. python 内置函数总结(大部分)

    python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就是pytho ...

  7. Python之路(第八篇)Python内置函数、zip()、max()、min()

    一.python内置函数 abs() 求绝对值 例子 print(abs(-2)) all() 把序列中每一个元素做布尔运算,如果全部都是true,就返回true, 但是如果是空字符串.空列表也返回t ...

  8. lambda 表达式+python内置函数

    #函数 def f1(a,b): retrun  a+b #lambda方式,形参(a,b):返回值(a+b) f2=lambda a,b : a+b 在一些比较简单的过程计算就可以用lambda p ...

  9. 【286】◀▶ Python 内置函数说明

    参考: Python 内置函数 01   abs() 返回数字的绝对值. 02   all() 用于判断给定的可迭代参数 iterable 中的所有元素是否不为 0.''.False 或者 itera ...

随机推荐

  1. .net core 2.x - 发送邮件

    前言 我们知道目前 .NET Core 还不支持 SMTP 协议,当我么在使用到发送邮件功能的时候,需要借助于一些第三方组件来达到目的,今天给大家介绍两款开源的邮件发送组件,它们分别是 MailKit ...

  2. Nginx 如何设置反向代理 多服务器,配置区分开来,单独文件保存单个服务器 server 主机名配置,通过 include 实现

    samcao 关注 2015.06.15 10:08* 字数 0 阅读 408评论 0喜欢 0   网络结构如上图.可能你只有一个公网的Ip地址. 但是您的内网有个网站需要映射至外网.而又不想添加其它 ...

  3. SQL反模式学习笔记5 外键约束【不用钥匙的入口】

    目标:简化数据库架构 一些开发人员不推荐使用引用完整性约束,可能不使用外键的原因有一下几点: 1.数据更新有可能和约束冲突: 2.当前的数据库设计如此灵活,以至于不支持引用完整性约束: 3.数据库为外 ...

  4. IE外挂

    //引用 Windows/system32/Shell32.dll //引用COM组件 shdocvw.dll (Microsoft Internet Controls) //引用COM组件 msht ...

  5. Java重头学

    前言:这两周来上了腾讯课堂-软媒-JAVA架构师黄埔班的课程后,发现自己真心是一个菜鸟,Java基础知识和日常开发所需的知识还有很多很多.就此,我准备跟着这个课程重头学习Java,成为一名合格的Jav ...

  6. oracle中可能使用到的命令

    借鉴他人 1.su – oracle 不是必需,适合于没有DBA密码时使用,可以不用密码来进入sqlplus界面.2.sqlplus /nolog 或sqlplus system/manager 或. ...

  7. Vue+localstrong登录注册,并保持登录状态

    在router.js中添加meta区分 比如登录注册页面,不需要登录即可进入,那么我们把meta中的isLogin标志设置为false { //登录 path: '/login', component ...

  8. 生产环境,vue页面跳转的时候,js报404的问题

    最近上线的一个vue项目,需要各种路由跳转,在开发和测试环境都没问题,但是在生产环境,发现后期更新代码的时候,有些机型(ios机型,暂未发现android有问题)跳转路由的时候,标题修改了,但是内容并 ...

  9. 纯 CSS 绘制三角形(各种角度)

     转载:https://www.cnblogs.com/lhb25/p/css-and-css3-triangle.html       Triangle Up #triangle-up { widt ...

  10. go web开发(gin&gorm) 之DB配置及DAO的基本使用

    转载请注明出处: https://www.cnblogs.com/funnyzpc/p/9501376.html ```   我先闲扯下,前天(也就是2018年11月16号)的某个时候,忽然有人在QQ ...