
python字典运算说明
1、字典运算中的键必须是不可变类型,如整数(int)、浮点数(float)、字符串(str)、元组(tuple)等。
2、列表(list)和集合(set)不能作为字典中的键,当然字典本身也不能作为字典中的键。
因为字典也是可变类型,但字典可以作为字典中的值。
python字典运算实例
student1 = {
'id': 1010,
'name': 'ipipgo',
'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字典进行运算的方法,希望对大家有所帮助。
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试



