英文文档:

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内置函数(23)——dict的更多相关文章

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

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

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

    英文文档: format(value[, format_spec]) Convert a value to a “formatted” representation, as controlled by ...

  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 内置函数总结(大部分)

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

  6. Python补充--Python内置函数清单

    Python内置函数 Python内置(built-in)函数随着python解释器的运行而创建.在Python的程序中,你可以随时调用这些函数,不需要定义.最常见的内置函数是: print(&quo ...

  7. 学习过程中遇到的python内置函数,后续遇到会继续补充进去

    1.python内置函数isinstance(数字,数字类型),判断一个数字的数字类型(int,float,comple).是,返回True,否,返回False2.python内置函数id()可以查看 ...

  8. Python入门之 Python内置函数

    Python入门之 Python内置函数 函数就是以功能为导向,一个函数封装一个功能,那么Python将一些常用的功能(比如len)给我们封装成了一个一个的函数,供我们使用,他们不仅效率高(底层都是用 ...

  9. Python内置函数和内置常量

    Python内置函数 1.abs(x) 返回一个数的绝对值.实参可以是整数或浮点数.如果实参是一个复数,返回它的模. 2.all(iterable) 如果 iterable 的所有元素为真(或迭代器为 ...

随机推荐

  1. 画一个DIV并给它的四个角变成圆形,且加上阴影

    <!doctype html><html><head><meta charset="utf-8"><title>无标题文 ...

  2. select函数的介绍和使用

    我们所使用的I/O模型一共有五种. 分别为阻塞I/O,非阻塞I/O,I/O复用,信号驱动I/O,异步I/O. 所谓I/O复用就是指管理多个I/O文件描述符,一般会使用(select,poll,epol ...

  3. UWP 调用系统拍照程序

    当需要用户选择照片时,一般有两种方法: 1.从本地磁盘选择 2.调用照相机拍照 这次就说一下第二种方法,毕竟第一种大家都会. 先看下效果 如图所示,点击拍照后,会弹出系统照相机界面,在手机上,会打开相 ...

  4. Liveness 探测 - 每天5分钟玩转 Docker 容器技术(143)

    Liveness 探测让用户可以自定义判断容器是否健康的条件.如果探测失败,Kubernetes 就会重启容器. 还是举例说明,创建如下 Pod: 启动进程首先创建文件 /tmp/healthy,30 ...

  5. Excel IF函数怎么用

    本例主要介绍Excel表格中IF函数的用法,包括基本用法.单条件.多条件表达及在数组函数中的用法和在数组函数中怎么表达多条件和单条件. 工具/原料   Excel IF函数语法介绍:   1 IF函数 ...

  6. Xshell提示缺失mfc110.dll

    xshell  应用程序无法正常启动0xc000007b    下载 DirectX修复工具_3.3 Xshell 缺少 mfc110.dll     https://www.microsoft.co ...

  7. shell脚本中文件测试

    shell脚本中文件测试 author:headsen chen  2017-10-17  14:35:19 个人原创,转载请注明作者,否则 依法追究法律责任 [ -f  filename  ]   ...

  8. 我的linux一万小时

    这不是一篇鸡汤文,因为我并没有在使用 Linux 一万小时后成为 Linux 达人,甚至在很多方面,我连新手都算不上.我走的这些弯路能篇成一本很有参考价值的反面教材,下面,我在www.itxdl.cn ...

  9. es6学习笔记--新数据结构Set,Map以及WeakSet,WeakMap

    在javascript中,存储数据的方式大部分就是以数组或者对象形式存储的,es6出现了4种新集合Set,Map,WeakSet,WeakMap来存储数据,简化了编程. 集合--Set 类似于数组,但 ...

  10. 多进程浏览器、多线程页面渲染与js的单线程

    线程与进程 说到单线程,就得从操作系统进程开始说起.在早期的操作系统中并没有线程的概念,进程是能拥有资源和独立运行的最小单位,也是程序执行的最小单位.任务调度采用的是时间片轮转的抢占式调度方式,而进程 ...