<p>我想知道如果我有一个字典,我想打印出一个特定键的值,我在Python中做什么。</p>
<p>它将包含在变量中以及:</p>
<pre><code>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.
</code></pre>
<p>我正在运行Python 3.3</p>
<p>在Python 3中:</p>
<pre><code># A simple dictionary
x = {'X':"yes", 'Y':"no", 'Z':"ok"}
# To print a specific value
print([value for value in x.values()][1])
</code></pre>
<p>输出:</p>
<pre><code>no
</code></pre>