题解 | #遍历字典#

遍历字典

https://www.nowcoder.com/practice/0315639767824323a2cdb9ee3f998314

#!/usr/local/bin/python3
#遍历字典
operator_dict = {'<':'less than' ,'==':'equal'}
print('Here is the original dict:')
(operator_dict)
 
for i in sorted(operator_dict):
    print(f"Operator {i} means {operator_dict[i]}.")
    
operator_dict['>'] = 'greater than'
print()
print('The dict was changed to:')

for i in sorted(operator_dict):
    print(f"Operator {i} means {operator_dict[i]}.")
    




    
新增一个知识点,输出的时候使用f""里面能直接使用索引输出字典的键和值。
全部评论

相关推荐

水墨不写bug:疑似没有上过大学
点赞 评论 收藏
分享
每晚夜里独自颤抖:要求太多的没必要理
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务