在if语句中处理多个“或”的更好方法

时间:2018-12-11 17:41:33

标签: python python-3.x

所以这将是一个愚蠢的问题,什么是更容易接受的措辞方式:

    if Answer1 == ("Register") or Answer1 == ("register") or Answer1 == 
    ("rgister") or Answer1 == ("Registe"):

在列表中?

1 个答案:

答案 0 :(得分:0)

您可以在列表中使用in

if Answer1 in ["Register", "register", "rgister", "Registe"]:

>>> if Answer1 in ["Register", "register", "rgister", "Registe"]:
...   print "OK"
... else:
...   print "NO"
... 
NO