python字典如何进行运算
发布时间:2024-07-04 14:31:55

说明
1、字典运算中的键必须是不可变的类型,例如整数(int)、浮点数(float)、字符串(str)、元组(tuple)等。
2、列表(list)和集合(set)不能作为字典中的键,当然字典本身也不能作为字典中的键。
因为字典也是可变类型,但字典可以作为字典中的值。
实例
student1={
'id':1010,
'name':'小明',
'sex':'True',
'birthday':'2000-1-1'
}
#遍历字典中的键
forkeyinstudent1:"""
print(key,student1[key])
#遍历字典中的值
forvalueinstudentt1.values():
print(value)
#字典中的键值是对的
forkey,valueinstudent1.items():
print(key,value)以上是计算python字典的方法,希望对大家有所帮助。更多Python学习指导:python基础教程
本文教程操作环境:windows7系统Python 3.9.1,DELL G3电脑。
下一篇 Python解释器有哪些种类
