英文文档:

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. 设计完美的策略模式,消除If-else

    策略模式是oop中最著名的设计模式之一,是对方法行为的抽象,可以归类为行为设计模式,也是oop中interface经典的应用.其特点简单又实用,是我最喜欢的模式之一.策略模式定义了一个拥有共同行为的算 ...

  2. g_thread_init

    NAME g_thread_init - 初始化线程系统 SYNOPSIS #include <glib.h> //in gthread.h void g_thread_init (GTh ...

  3. Java重头学

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

  4. Final Cut Pro X for Mac(FCPX专业视频剪辑工具)实用技巧篇!

    Final Cut Pro X for Mac是一款非常强大的专业视频剪辑工具,全球很多人都在用!现在小编给大家带来一些关于Final Cut Pro X for Mac的使用技巧,希望对大家以后的应 ...

  5. Shell编程-控制结构 | 基础篇

    if-then-else分支结构 if-then-else是一种基于条件测试结果的流程控制结构.如果测试结果为真,则执行控制结构中相应的命令列表:否则将进行另外一个条件测试或者退出该控制结构. if- ...

  6. 20181115 python-第一章学习小结part3

    第一章,基本数据类型-------仅学三种,字符型,数字型,布尔型 仅学三种数据类型: 字符型,加了引号的都可以被认为是字符串,字符串可以拼接 数字型,int,float,long三种,可以进行运算 ...

  7. VMware手动添加centos7硬盘图文操作及分区超详细

    先设置虚拟机 启动的虚拟机,新关机再设置 1.选择指定虚拟机,点击硬盘 2.虚拟机设置,点击左下角“添加” 3.硬件类型选择硬盘,点击下一步 4.添加硬件向导默认就行,下一步 5.选择磁盘,默认选中, ...

  8. 使用POST下载文件

    一直以来,JS都没有比较好的可以直接处理二进制的方法.而Blob的存在,允许我们可以通过JS直接操作二进制数据.一.下载util.fetchDownload= function (opt,data) ...

  9. LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++>

    LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++> 给出排序好的一维数组,如果一个元素重复出现的次数 ...

  10. C语言表达式和语句

    一.表达式 在C语言中,常量.变量.函数调用以及按C语言语法规则用运算符把运算数连接起来的式子都是合法的表达式 . 最后一类可以理解为运算符和运算对象的组合.例如: 算术表达式 = 算术运算符 + 运 ...