擅长:python、mysql、java
<p>试着用这样的字典</p>
<pre><code>terms = {
'mass' : "the amount of matter in an object, base unit is kilograms",
'weight' : "the pull of gravity on a mass",
'volume' : "lenght x width x height"
}
</code></pre>
<p>当你必须访问某些东西时,只需使用</p>
<pre><code>terms[anyterm] #example terms['volume']
</code></pre>
<p>用于输入使用</p>
<pre><code>term = input('What you want to know more about')
print(terms[term]) # Notice no quotes to use a variable
</code></pre>
<p>或</p>
<pre><code>print(terms.get(term, 'Term not found')) # Second argument is to
# ensure that if term is not in dictionary then this will be the default value
</code></pre>