python用dict字典映射相当于switch语句
# 采用dict映射 def print_A(): print("A") def print_B(): print("A") def print_C(): print("A") score = 90 # switch = { # 90:print_A(), # 80:print_C() # } switch = { 90:lambda :print_A() } switch[score]()
# 采用dict映射 def print_A(): print("A") def print_B(): print("A") def print_C(): print("A") score = 90 # switch = { # 90:print_A(), # 80:print_C() # } switch = { 90:lambda :print_A() } switch[score]()