后浪云Python教程:python字典如何进行运算
说明
1、字典运算中的键必须是不可变类型,如整数(int)、浮点数(float)、字符串(str)、元组(tuple)等。
2、列表(list)和集合(set)不能作为字典中的键,当然字典本身也不能作为字典中的键。
因为字典也是可变类型,但字典可以作为字典中的值。
实例
student1 = { 'id': 1010, 'name': '小明', 'sex': 'True', 'birthday': '2000-1-1' } #遍历字典中的键 for key in student1: """ print(key, student1[key]) #遍历字典中的值 for value in student1.values(): print(value) #遍历字典中的键值对 for key, value in student1.items(): print(key, value)
以上就是python字典进行运算的方法,希望对大家有所帮助。更多Python学习指路:后浪云python教程
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
版权声明:
作者:后浪云
链接:https://www.idc.net/help/176135/
文章版权归作者所有,未经允许请勿转载。
THE END