当前位置: 首页 > 图灵资讯 > 行业资讯> python字典是什么

python字典是什么

发布时间:2024-08-14 11:19:56

1、概念

字典是通过名称引用值的数据结构,称为映射。字典中的值没有特殊的顺序,它们都存储在特定的键中(key)下面,键可以是数字、字符串甚至元组。字典也是python中唯一的内部映射类型。

2、格式

my_dict={key1:value1,key2:value2}

3、创建方法

(1)使用dict函数创建

items=[('name','god'),('age',42)]
d=dict(items)
print(d)
#结果是{'name':'god','age':42}
#如果不将数据传输到dict函数,它将创建一个空字典
t=dict()
print(t)
#结果为{}

(2)指定关键字参数创建字典

d=dict(name='god',age=12)
print(d)
#结果是{'name':'god','age':12}

以上是python字典的介绍。看完字典的基本内容,可以自己尝试创建字典。更多Python学习指导:python基础教程

(推荐操作系统:windows7系统Python 3.9.1,DELL G3电脑。)

相关文章

python3兼容python2吗

python3兼容python2吗

2025-05-09
python3 whl怎么安装

python3 whl怎么安装

2025-05-09
python 字典怎么提取value

python 字典怎么提取value

2025-05-09
python 怎样计算字符串的长度

python 怎样计算字符串的长度

2025-05-09
python 怎么样反向输出字符串

python 怎么样反向输出字符串

2025-05-09
python 怎么判断字符串开头

python 怎么判断字符串开头

2025-05-09