python中的 dict() 函数
dict() 函数函数语法: dict(key/value)
参数说明:
- key/value -- 用于创建字典的键/值对,此处可以表示键/值对的方法有很多,请看实例。
实例
以下实例展示了 dict() 函数的使用方法:
# !/usr/bin/python3
dict0 = dict() # 传一个空字典
print('dict0:', dict0) dict1 = dict({'three': 3, 'four': 4}) # 传一个字典
print('dict1:', dict1) dict2 = dict(five=5, six=6) # 传关键字
print('dict2:', dict2) dict3 = dict([('seven', 7), ('eight', 8)]) # 传一个包含一个或多个元祖的列表
print('dict3:', dict3) dict5 = dict(zip(['eleven', 'twelve'], [11, 12])) # 传一个zip()函数
print('dict5:', dict5)
以上实例输出结果为:
dict0: {}
dict1: {'four': 4, 'three': 3}
dict2: {'five': 5, 'six': 6}
dict3: {'seven': 7, 'eight': 8}
dict5: {'twelve': 12, 'eleven': 11}
python中的 dict() 函数的更多相关文章
- python --- Python中的callable 函数
python --- Python中的callable 函数 转自: http://archive.cnblogs.com/a/1798319/ Python中的callable 函数 callabl ...
- python中使用zip函数出现<zip object at 0x02A9E418>
在Python中使用zip函数,出现<zip object at 0x02A9E418>错误的原因是,你是用的是python2点多的版本,python3.0对python做了改动 zip方 ...
- [转载]python中multiprocessing.pool函数介绍
原文地址:http://blog.sina.com.cn/s/blog_5fa432b40101kwpi.html 作者:龙峰 摘自:http://hi.baidu.com/xjtukanif/blo ...
- Python 中的isinstance函数
解释: Python 中的isinstance函数,isinstance是Python中的一个内建函数 语法: isinstance(object, classinfo) 如果参数object是cla ...
- Python中的map()函数和reduce()函数的用法
Python中的map()函数和reduce()函数的用法 这篇文章主要介绍了Python中的map()函数和reduce()函数的用法,代码基于Python2.x版本,需要的朋友可以参考下 Py ...
- python中multiprocessing.pool函数介绍_正在拉磨_新浪博客
python中multiprocessing.pool函数介绍_正在拉磨_新浪博客 python中multiprocessing.pool函数介绍 (2010-06-10 03:46:5 ...
- 举例详解Python中的split()函数的使用方法
这篇文章主要介绍了举例详解Python中的split()函数的使用方法,split()函数的使用是Python学习当中的基础知识,通常用于将字符串切片并转换为列表,需要的朋友可以参考下 函数:sp ...
- python中的生成器函数是如何工作的?
以下内容基于python3.4 1. python中的普通函数是怎么运行的? 当一个python函数在执行时,它会在相应的python栈帧上运行,栈帧表示程序运行时函数调用栈中的某一帧.想要获得某个函 ...
- python中的map()函数
MapReduce的设计灵感来自于函数式编程,这里不打算提MapReduce,就拿python中的map()函数来学习一下. 文档中的介绍在这里: map(function, iterable, .. ...
随机推荐
- eth0: ERROR while getting interface flags: No such device的解决方法、Linux怎么修改IP以及ping不通的处理方法
首先输入ifconfig命令查看当前的ip信息 发现没有eth0这个网卡设备,有ens33 接着输入命令:ifconfig ens33 192.168.2.110 -- 修改临时ip地址,系统 ...
- Git 创建点开头的文件和目录
Git 创建点开头的文件和目录 # 创建 .gitignore 文件 1@DESKTOP-3H9092J MINGW64 /e/x1/x1/demo1 (master) $ echo .idea &g ...
- zzTensorflow技术内幕:
性能优势 TensorFlow在大规模分布式系统上的并行效率相当高,如下图所示: 图5:TensorFlow并发效率 在GPU数量小于16时,基本没有性能损耗,在50块的时候,可以获得80%的效率,也 ...
- LeetCode 110. Balanced Binary Tree平衡二叉树 (C++)
题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bin ...
- Spring Cloud版本 version命名说明 (Edgware)
Spring Cloud版本 version命名说明 (Edgware) 版权声明:guofangsky 版权所有,转载不究. https://blog.csdn.net/guofangsky/a ...
- mark-杭州互联网公司分布-位置信息
项目内容: 在智联招聘上爬取杭州市互联网公司的位置信息,属于哪个区: 如果公司信息内不含区信息,则通过百度地图接口获取所属区信息 scrapy+pycharm
- 开源推荐 - CoDo开源一站式DevOps平台
一群有梦想的年轻人开源了一个云管理平台,他们的口号是:让天下没有996的运维 有幸参与到CoDo项目的开发,这是一个非常棒的一站式开源运维平台,分享给大家 平台介绍 CODO是一款为用户提供企业多混合 ...
- [BJOI2014]想法(随机算法,神奇思路,拓扑排序)
对于这种随机数据或者随机算法的题-- 都是神仙题吧. 要求的就是对每个点前 \(m\) 个点中有多少个可以到达它. 由于评分方式这么奇怪,不妨考虑随机. 随机 127 次(可以选别的数,够多而且不 T ...
- [LeetCode] 864. Shortest Path to Get All Keys 获得所有钥匙的最短路径
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@& ...
- [LeetCode] 518. Coin Change 2 硬币找零之二
You are given coins of different denominations and a total amount of money. Write a function to comp ...