我想知道如果我有一个字典,我想打印出一个特定键的值,我在Python中做什么。
它将包含在变量中以及:
dict = {'Lemonade':["1", "45", "87"], 'Coke:["23", "9", "23"] 'Water':["98", "2", "127"}
inp = input("Select key to print value for!" + "/r>>> ")
if inp in dict:
#Here is where I would like it to print the Value list for the key that is entered.
我正在运行Python 3.3
正如Ashwini指出的,你的字典应该是
{'Lemonade':["1", "45", "87"], 'Coke':["23", "9", "23"], 'Water':["98", "2", "127"]}
要打印值:
另外,不要使用
dict
作为变量,因为它将重写内置类型,并且可能在以后引起问题。我冒昧地重命名了
dict
变量,以避免隐藏内置名称。在Python 3中:
输出:
相关问题 更多 >
编程相关推荐