擅长:python、mysql、java
<p>您可以使用<code>callable()</code>函数来测试字典值是否为函数。如果是,则调用它,否则只需打印值本身</p>
<pre><code>def mainfunction():
dict = {
'x' : secondfunc,
'y' : 'hello world'
}
while True:
inpt = input('@')
z = dict.get(inpt, 'Default text')
if callable(z):
z()
else:
print(z)
</code></pre>