【程序分析】
● 字典中的条目是没有顺序的。
● 可以对字典使用如下方法: keys()、values()、 items()、 clear()、 get(key)、 pop(key) 和popitem()
【程序代码】
dictionary={"dog":"狗","apple":"苹果","banana":"香蕉","cat":"猫","peach":"桃子"
}def find(word):return dictionary.get(word, "Sorry,no finding.")while True:x=input("Please input a word (input q to exit):")if x=="q":breakmeaning=find(x)#print(f"{x}'s meaning:{meaning}")print("{}'s meaning:{}".format(x,meaning))
【程序输出】
Please input a word (input q to exit):dog
dog's meaning:狗
Please input a word (input q to exit):cat
cat's meaning:猫
Please input a word (input q to exit):op
op's meaning:Sorry,no finding.
Please input a word (input q to exit):q
>>>