例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")
浙公网安备 33010602011771号