英文文档:

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. 大数据(1):基于sogou.500w.utf8数据的MapReduce程序设计

    环境:centos7+hadoop2.5.2 1.使用ECLIPS具打包运行WORDCOUNT实例,统计莎士比亚文集各单词计数(文件SHAKESPEARE.TXT). ①WorldCount.java ...

  2. Spring源码学习:第0步--环境准备

    Spring源码现在已托管于GitHub,相比于以前直接从官网下载一个压缩包的方式来说,确实方便了不少. GitHub地址:https://github.com/spring-projects/spr ...

  3. nginx里的sticky的作用

    1.Sticky工作原理 : Sticky是nginx的一个模块,它是基于cookie的一种nginx的负载均衡解决方案,通过分发和识别cookie,来使同一个客户端的请求落在同一台服务器上,默认标识 ...

  4. 归档日志空间满导致DB启动失败

    现象 登录失败 告警日志: 由此可知,归档日志空间已满 解决方式: 一.增大归档日志空间 1.启动数据库至nomount [oracle@CentOS ~]$ sqlplus / as sysdba ...

  5. 剑指Offer-把二叉树打印成多行

    package Tree; import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; /** * ...

  6. java安全框架shiro(一)

    第一个简单的案例 ,通过读取.ini文件的方式模拟登陆, 1.通过Factory工厂的getInstance()方法来获取SecurityManager的实例,实例化Factory需要一个ini文件的 ...

  7. 前端touch事件方向的判断

    移动端touch事件判断滑屏手势的方向 方法一 当开始一个touchstart事件的时候,获取此刻手指的横坐标startX和纵坐标startY: 当触发touchmove事件时,在获取此时手指的横坐标 ...

  8. 避免uncaughtException错误引起node.js进程崩溃

    uncaughtException 未捕获的异常, 当node.js 遇到这个错误,整个进程直接崩溃. 或许这俩个人上辈子一定是一对冤家. 或许这俩个人经历了前世500次的回眸才换来了今生的相遇,只可 ...

  9. python基础学习笔记一

    1.变量 为了节省内存,python解释器会对一些简单的字符串以及小整型数,做出一些优化,当要定义的新变量的内容与定义过的内容相同时,会让两者使用同一个内存空间. 例如: 在这个例子里面,'old'是 ...

  10. 机器学习(1) - TensorflowSharp 简单使用与KNN识别MNIST流程

    机器学习是时下非常流行的话题,而Tensorflow是机器学习中最有名的工具包.TensorflowSharp是Tensorflow的C#语言表述.本文会对TensorflowSharp的使用进行一个 ...