【发布时间】:2019-11-18 11:29:09
【问题描述】:
我试图在 Python 中实现 switch-case 语句。我需要帮助,因为这不会在控制台上打印任何内容。我想用这个开关触发一些功能。
def do_something():
print("do")
def take_something():
print("take")
switch = {
"do": do_something,
"take": take_something
}
def execute_command(command):
switch.get(command, lambda: print("Invalid command!"))
execute_command(input())
【问题讨论】:
-
你永远不会调用函数...
标签: python python-3.x