首页 技术 正文
技术 2022年11月10日
0 收藏 547 点赞 4,569 浏览 594 个字

Python dict() 函数

Python dict() 函数 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 dict() 函数 Python 内置函数

 Python OS 文件/目录方法Python 面向对象  

1 篇笔记 写笔记

  1. myelsa

    945***25@qq.com

    利用 dict(([key,value],[key,value])) 的方式创建字典:

    >>> dict((['a',2],['b',3]))
    {'a': 2, 'b': 3}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,188
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,647
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,489
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,263
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,901
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,064