python中dict[key] 存在key,但是报错:KeyError

改为:

dict.get(key)

dict = {'Name': 'Runoob', 'Age': 27}

print "Value : %s" %  dict.get('Age')
print "Value : %s" %  dict.get('Sex', "Not Available")

你可能感兴趣的:(python)