我的代碼工作它創建了一個列表,然後同時採用「或」與「和」的條件做進一步的動作:嵌套「和/或」 if語句
a= ["john", "carlos", "22", "70"]
if (("qjohn" or "carlos") in a) and (("272" or "70") in a):
print "true"
else:
print "not true"
輸出:
not true
當我這樣做:
a= ["john", "carlos", "22", "70"]
if ("qjohn" or "cdarlos" in a) and ("272" or "d70" in a):
print "true"
else:
print "not true"
輸出"true"
我沒有得到的是**carlos and 70**
應該等於true,但它打印「不正確」。這個錯誤的原因是什麼?謝謝
並不完全是欺騙,但具有相同的基本問題涉及:如何測試對多值一個變量? ](https://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-multiple-values) – glibdud