英文文档:

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. python写一个信息收集四大件的脚本

    0x0前言: 带来一首小歌: 之前看了小迪老师讲的课,仔细做了些笔记 然后打算将其写成一个脚本. 0x01准备: requests模块 socket模块 optparser模块 time模块 0x02 ...

  2. python引用和对象详解

    python引用和对象详解 @[马克飞象] python中变量名和对象是分离的 例子 1: a = 1 这是一个简单的赋值语句,整数 1 为一个对象,a 是一个引用,利用赋值语句,引用a指向了对象1. ...

  3. Unity3D脚本的生命周期(执行顺序)

    Unity脚本中有许多固定的函数 例如Start();Update(); 而这些函数都有固定的执行顺序 搞清楚这些函数的执行顺序 对于我们理清代码的逻辑就显得尤为重要 举个简单的例子 //脚本A pu ...

  4. iOS加密算法总结

    常用加密算法: DES:Data Encryption Standard,即数据加密算法,它是IBM公司于1975年研究成功并公开发表的. DES(数据加密标准)原理: DES是一个分组加密算法,它以 ...

  5. java 常用正则表达式总结

    邮政编码: ^[1-9]\d{5}$ QQ号码: ^[1-9]\d{4,10}$ 或者:[1-9][0-9]{4,11} 邮箱: ^[a-zA-Z_]{1,}[0-9]{0,}@(([a-zA-z0- ...

  6. C++环境搭建与atom编译器编译C++

    Windows下安装 方法一--VS: 使用windows开发神器visio studio.这种方法比较简单,直接下载一个最新的vs安装就行.不单单是C++,C.C#.VB等都可以开发. 方法二--只 ...

  7. thinkphp5 taglib自定义标签教程

    学着写了一下,终于搞定了,顺便分享一下!taglib是tp框架自定义标签功能,如果你用过cms,肯定见过类似: {dede:arclist typeid='' row='' col='' titlel ...

  8. Day3--------------目录文件的浏览、管理及维护

    1.pwd命令功能 2.cd命令功能 cd..      返回上一级 cd~ cd- 返回上一次的目录 cd 3.ls命令功能 ls -a ls -all ls -l 4.cp命令功能 cp -i 覆 ...

  9. 【Python】 sys和os模块

    sys sys模块能使程序访问于python解释器联系紧密的变量和函数 ● sys中的一些函数和变量 argv 命令行参数构成的列表 path 查找所有可用模块所在的目录名的列表 platform 查 ...

  10. Zabbix常用key和自定义key的讲解

    zabbix中常用到的几个key: 1.监控端口的:net.tcp.port[,3306],可以在服务器端对被监控端测试. /usr/local/zabbix/bin/ -s192.168.8.120 ...