以下程序的输出结果是( )。  d={’food’:{’cake’:1,’egg’:5}}  print(d.get(’egg’,’no this food’))

admin2022-09-09  10

问题 以下程序的输出结果是(          )。
 d={’food’:{’cake’:1,’egg’:5}}
 print(d.get(’egg’,’no this food’))

选项 A、egg
B、1
C、food
D、no this food

答案D

解析 根据字典的索引方式可知,d.get(’egg’,’no this food’)索引的是字典第一层,但是第一层只有键food,没有键egg,故索引不出值,输出的是no this food。本题选择D选项。
转载请注明原文地址:https://kaotiyun.com/show/bZ6p777K
0

最新回复(0)