# 字典的赋值操作
operators_dict ={
'<': 'less than',
'==': 'equal'
}
print('Here is the original dict:')
# dict.keys() 可以返回字典所有的键
# dict.values() 返回字典所有的键值
# dict.items() 返回字典的键值对
for key in sorted(operators_dict.keys()):
print(f'Operator {key} means {operators_dict[key]}.')
print()
# 增加键值对
operators_dict['>']='greater than'
print('The dict was changed to:')
for key in sorted(operators_dict.keys()):
print(f'Operator {key} means {operators_dict[key]}.')

京公网安备 11010502036488号