Python - 字典

空字典

empty = {}

字典遍历

  • 遍历所有键
calorie = {'apple': 54, 'orange': 44, 'banana': 93}
for key in calorie.keys():
    print(key)
  • 遍历所有值
calorie = {'apple': 54, 'orange': 44, 'banana': 93}
for value in calorie.values():
    print(value)
  • 遍历所有键值对
calorie = {'apple': 54, 'orange': 44, 'banana': 93}
for key, value in calorie.items():
    print(key, value)

你可能感兴趣的:(Python - 字典)