【发布时间】:2017-05-02 16:36:16
【问题描述】:
我有多种情况:
if you == 1 or you == 2:
one.put(argument)
elif you == 3:
return None
elif you == 4:
two.put(argument)
elif you == 5:
three.put(argument)
elif you == 6:
four.put(argument)
elif you == 7:
five.put(argument)
elif you == 8:
six.put(argument)
elif you == 9:
seven.put(argument)
elif you == 10:
eight.put(argument)
elif you == 11:
nine.put(argument)
elif you == 12:
ten.put(argument)
我想将其更改为使用字典,但出现以下异常:
if you == 1 or you == 2:
one.put(argument)
elif you == 3:
return None
最好的方法是什么?
【问题讨论】:
-
你应该在codereview.stackexchange.com上问这个
-
有什么例外?
-
也许吧,但我正在学习。我还不是专业的开发人员
-
@DeepSpace 从第一行到第四行。不一样,我们在第四行之后使用
-
所以我写了一篇关于过去使用python字典而不是if-else语句的博客。你可以阅读它here
标签: python python-3.x for-loop if-statement