Python内置函数(23)——dict
英文文档:
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的更多相关文章
- Python内置函数(15)——dict
英文文档: class dict(**kwarg) class dict(mapping, **kwarg) class dict(iterable, **kwarg) Return a new di ...
- Python内置函数(23)——format
英文文档: format(value[, format_spec]) Convert a value to a “formatted” representation, as controlled by ...
- python内置函数之dict()
class dict(**kwargs) 返回一个字典.本方法用来创建一个字典对象.只能传入一个参数. >>> dict(a=1) {'a': 1} 也可以传入映射函数作为参数 &g ...
- 【转】python 内置函数总结(大部分)
[转]python 内置函数总结(大部分) python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为 ...
- python 内置函数总结(大部分)
python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就是pytho ...
- Python补充--Python内置函数清单
Python内置函数 Python内置(built-in)函数随着python解释器的运行而创建.在Python的程序中,你可以随时调用这些函数,不需要定义.最常见的内置函数是: print(&quo ...
- 学习过程中遇到的python内置函数,后续遇到会继续补充进去
1.python内置函数isinstance(数字,数字类型),判断一个数字的数字类型(int,float,comple).是,返回True,否,返回False2.python内置函数id()可以查看 ...
- Python入门之 Python内置函数
Python入门之 Python内置函数 函数就是以功能为导向,一个函数封装一个功能,那么Python将一些常用的功能(比如len)给我们封装成了一个一个的函数,供我们使用,他们不仅效率高(底层都是用 ...
- Python内置函数和内置常量
Python内置函数 1.abs(x) 返回一个数的绝对值.实参可以是整数或浮点数.如果实参是一个复数,返回它的模. 2.all(iterable) 如果 iterable 的所有元素为真(或迭代器为 ...
随机推荐
- Android OpenGL ES 开发(九): OpenGL ES 纹理贴图
一.概念 一般说来,纹理是表示物体表面的一幅或几幅二维图形,也称纹理贴图(texture).当把纹理按照特定的方式映射到物体表面上的时候,能使物体看上去更加真实.当前流行的图形系统中,纹理绘制已经成为 ...
- 利用EF Core的Join进行多表查询
背景 话说有这么一家子,老公养了一条狗,老婆养了一只猫. 数据库的设计 人表 宠物表 通过表可以知道,宠物通过Owner指向主人的Id. 问题来了,我要和故事开头一样,老公-狗,老婆-猫,对应起来,怎 ...
- Go实现短url项目
首先说一下这种业务的应用场景: 把一个长url转换为一个短url网址 主要用于微博,二维码,等有字数限制的场景 主要实现的功能分析: 把长url的地址转换为短url地址 通过短url获取对应的原始长u ...
- Hadoop 2.6.0-cdh5.4.0集群环境搭建和Apache-Hive、Sqoop的安装
搭建此环境主要用来hadoop的学习,因此我们的操作直接在root用户下,不涉及HA. Software: Hadoop 2.6.0-cdh5.4.0 Apache-hive-2.1.0-bin Sq ...
- 三方面搞定http协议之“状态码”
当我们向服务器请求数据的时候,服务器会给我们一个反馈,告诉我们对待我们的请求,服务器处理得怎么样了,而这个反馈,是通过数字来传达的,这个数字就叫状态码. 状态码分为以下几种: 1xx:指示信息--表示 ...
- Docker国内镜像源设置
编辑json文件,添加如下内容后重启docker即可. [root@Docker ~]# cat /etc/docker/daemon.json{ "registry-mirrors&quo ...
- 关于html表单的disabled属性的设置问题
首先,我的看法是无论disable的值是否有值,只要设置了disabled属性的表单,无论是否有值,无论值为什么,都会被禁用. 来看下面例子: 在一个群里有人说因为直接写在表单属性上是字符串,因为 ...
- Javascript中几个看起来简单,却不一定会做的题
Javascript作为前端开发必须掌握的一门语言,因为语言的灵活性,有些知识点看起来简单,在真正遇到的时候,却不一定会直接做出来,今天我们就一起来看看几道题目吧 题目1 var val = 'smt ...
- android中shape属性大全
出处:http://kofi1122.blog.51cto.com/2815761/521605
- h5移动端屏幕适配
1.rem <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...