<分区> 分区>
示例 1 - 这有效:
def thisorthat():
var = 2
if (var == 3 or var == 2):
print "i see the second value"
elif (var == 2 or var == 15):
print "I don't see the second value"
thisorthat()
示例 2 - 这不起作用:
def thisorthat():
var = 2
if var == (3 or 2):
print "i see the second value"
elif var == (2 or 15):
print "I don't see the second value"
thisorthat() # "I don't see the second value"
有没有一种方法可以将变量与“或”运算符进行比较,而无需在每一行中重复变量两次?
