关于get()的用法
程序代码:
eople = { 'alice' : { 'phone': '2341', 'addr' : 'foo drive 23' }, 'beth' : { 'phone' : '9102', 'addr' : 'bar street 42' }, 'cecil' : { 'phone' : '3158', 'addr' : 'baz avenue 90' } } labels = { 'phone' : 'phone number', 'addr' : 'address' } name = raw_input('name: ') request = raw_input('phone number (p) or address(a)?') key = request if request == 'p' : key = 'phone' if request == 'a' : key = 'addr' person = people.get(name,{}) label = labels.get(key,key) result = person.get(key, 'not available') print "%s's %s is %s." % (name,label,result) #if name in people : print "%s's %s is %s." % (name,labels[key], people[name][key])
最近开始学python基础教程这本书,今天看到get()的用法有点懵,想问一下倒数第5行代码,为什么people字典中没有name键的时候要返回一个空字典,作用是什么?