我試過谷歌,但我找不到這個簡單問題的答案。 我討厭自己無法弄清楚這一點,但我們現在就去。我的「if」陳述中的「or」有什麼問題?
如何在or
中編寫if語句?
例如:
if raw_input=="dog" or "cat" or "small bird":
print "You can have this animal in your house"
else:
print "I'm afraid you can't have this animal in your house."
您的示例代碼爲「或」荷蘭國際集團的字符串,這是不合法的操作。 – marr75 2010-08-02 14:44:33
@marr它實際上是在執行'(raw_input =='dog')或'cat'或'small bird'',所以如果'raw_input =='dog''或'cat'返回'True' – 2010-08-02 14:45:55
Oops ,你是對的,那將永遠執行。它是or'ing字符串,但這將評估爲「貓」每次,因爲貓是一個字符串,不是空的,它會算作真實的。 – marr75 2010-08-03 04:41:11