【发布时间】:2020-09-17 17:29:46
【问题描述】:
我正在尝试根据 4 个输入变量的值从我创建的 16 个字典中选择一个。
我认为可以通过 switch 完成,但到目前为止我还没有得到它。
我认为“逻辑”可能与此类似:
variable_1 = 0
variable_2 = 1
variable_3 = 1
variable_4 = 0
def func_select_dict(variable_1, variable_2, variable_3, variable_4)
switch(0,0,0,0):
final_dictionary = dictionary_1
switch(0,0,0,1):
final_dictionary = dictionary_2
switch(0,0,1,0):
final_dictionary = dictionary_3
...............
switch(1,1,1,1):
final_dictionary = dictionary_16
有什么想法吗?
【问题讨论】:
-
Python 没有 switch case 语句,所以你可能需要重新考虑。
-
这能回答你的问题吗? Why doesn't Python have switch-case?
标签: python conditional-statements