姬長信(Redy)

python – 使用与IF语句的OR比较


参见英文答案 > How to test multiple variables against a value?????????????????????????????????????21个
在Python中使用IF语句时,必须执行以下操作才能使“级联”正常工作.
if job == "mechanic" or job == "tech":
        print "awesome"
elif job == "tool" or job == "rock":
        print "dolt"

有没有办法让Python在检查“等于”时接受多个值?例如,

if job == "mechanic" or "tech":
    print "awesome"
elif job == "tool" or "rock":
    print "dolt"