创建字典operators_dict
operators_dict = {'<': 'less than', '==': 'equal'}
遍历排序后的字典进行信息打印
print('Here is the original dict:')
for m, n in sorted(operators_dict.items()):
print('Operator %s means %s.' % (m, n))
在字典中添加新的键值对
operators_dict['>'] = 'greater than'
换行并再次进行遍历排序后的字典进行信息打印
print()
print('The dict was changed to:')
for o, p in sorted(operators_dict.items()):
print('Operator %s means %s.' % (o, p))

京公网安备 11010502036488号