我有一个Python程序,需要用户输入.我存储用户输入一个名为"userInput"的字符串变量.我希望能够调用用户输入的字符串...
userInput = input("Enter a command: ")
userInput()
Run Code Online (Sandbox Code Playgroud)
从这里,我得到错误:TypeError:'str'对象不可调用
目前,我有程序做这样的事情:
userInput = input("Enter a command: ")
if userInput == 'example_command':
example_command()
def example_command():
print('Hello World!')
Run Code Online (Sandbox Code Playgroud)
显然,这不是处理大量命令的非常有效的方法.我想让str obj可以调用 - 无论如何这样做?