×
Python 基础教程Python 简介Python 环境搭建Python 中文编码Python 基础语法Python 变量类型Python 运算符Python 条件语句Python 循环语句Python While循环语句Python for 循环语句Python 循环嵌套Python break 语句Python continue 语句Python pass 语句Python 数字Python 字符串Python 列表(Lists)Python 元组Python 字典(Dictionary)Python 日期和时间Python 函数Python 模块Python 文件I/OPython File(文件) 方法Python 异常处理Python OS 文件/目录方法Python 内置函数

Python 高级教程

Python 面向对象Python 正则表达式Python CGI编程python MysqlPython SMTPPython 多线程Python XML解析python GUI编程(Tkinter)Python 2.x与3​​.x版本区别Python IDEPython JSONPython 100例

Python dict() 函数


Python 内置函数Python 内置函数


描述

dict() 函数用于创建一个字典。

语法

dict 语法:

class dict(**kwarg)
class dict(mapping, **kwarg)
class dict(iterable, **kwarg)

参数说明:

  • **kwargs -- 关键字
  • mapping -- 元素的容器。
  • iterable -- 可迭代对象。

返回值

返回一个字典。

实例

以下实例展示了 dict 的使用方法:

>>>dict() # 创建空字典 {} >>> dict(a='a', b='b', t='t') # 传入关键字 {'a': 'a', 'b': 'b', 't': 't'} >>> dict(zip(['one', 'two', 'three'], [1, 2, 3])) # 映射函数方式来构造字典 {'three': 3, 'two': 2, 'one': 1} >>> dict([('one', 1), ('two', 2), ('three', 3)]) # 可迭代对象方式来构造字典 {'three': 3, 'two': 2, 'one': 1} >>>

Python 内置函数Python 内置函数


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)