例2.9 字典的get()方法使用示例

例2.9 字典的get()方法使用示例

点击查看代码
Dict={'age':18,'score':[98,97],'name':'Zhang','sex':'male'}
print(Dict['age'])          #输出18
print(Dict.get('age'))      #输出18
print(Dict.get('address','Not Exists.'))   #输出No Exists 
try:  
    print(Dict['address'])  
except KeyError:  
    print('Key "address" does not exist in the dictionary.')

print("学号:3004")

posted on 2024-09-06 13:33  黄元元  阅读(47)  评论(0)    收藏  举报