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 的所有元素为真(或迭代器为 ...
随机推荐
- 【技术】关于安卓使用禁用服务(或者是MYANDROIDTOOLS里面的禁用服务)后卡在开机页面的(或者是卡在各种页面的)
目前会出现禁用部分服务后卡在开机页面,导致到手机数据得全部清除在网上找了很久,都没找到还原的方法只好自己开垦新方案了推测:由于格式化DATA分区后,手机可以正常开机,所以认为禁用服务的配置内容保存在D ...
- Python爬虫获取异步加载站点pexels并下载图片(Python爬虫实战3)
1. 异步加载爬虫 对于静态页面爬虫很容易获取到站点的数据内容,然而静态页面需要全量加载站点的所有数据,对于网站的访问和带宽是巨大的挑战,对于高并发和大访问访问量的站点来说,需要使用AJAX相关的技术 ...
- doT.js——前端javascript模板引擎问题备忘录
我手里维护的一个项目,遇到一个问题:原项目的开发人员在Javascript中,大量的拼接HTML,导致代码极丑,极难维护.他们怎么能够忍受的了这么丑陋.拙劣的代码呢,也许是他们的忍受力极强,压根就没想 ...
- Git -- 分支与合并 (命令行+可视化工具p4merge)
基本命令 把所有的变化都放在master分支并不是最好的做法. 建议的做法是把变化放在分支里面. 至少应该准备一个feature分支之类的, 把变化都隔离开来, 然后等到所有的功能都稳定之后再合并到m ...
- pxe自动化批量安装系统(Centos7)
PXE:preboot execute environment 环境实现:主服务器ip:10.0.10.1 1 tfpt trivial简单文件共享服务,基于udp协议工作: 加载系统安装程序: 69 ...
- python为运维人员打造一个监控脚本
0x00前言: 一直想写一个监控方面的脚本,然后想到了运维这方面的 后来就写了个脚本. 0x001准备: psutil模块 0x02正文: import os import time import r ...
- 笔记:Spring Cloud Eureka 常用配置及说明
配置参数 默认值 说明 服务注册中心配置 Bean类:org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean ...
- eclipse打包
- python统计词频
arr = [1,2,3,4,5,6,4,5,2,3,6,8,9,6,5,3,6,2,4]dic={}for item in arr: if item in dic.keys(): dic[item] ...
- jenkins忘记密码怎么办?
在nginx配置文件中加上域名访问,重定向到本机的8080端口. server { listen 80; server_name tomcat.qinyj.top; root /application ...