2016-12-26 32 views
-2

我是Python新手,目前正在學習有關AND,OR,而不是運算符。以下是我編寫的示例程序,用於瞭解這些操作員如何與if-else命令一起使用。在Python中使用AND運算符沒有得到期望的輸出

a=4 
b=7 

if a=="4" and b=="7": 
    print "Good work.. keep it up!" 
else: 
    print "Find the problem and solve it!" 

我得到的輸出不是我所期望的。這是Find the problem and solve it!。我不明白。由於我的條件(a == 4 nad b == 7)都滿足,爲什麼我會得到else輸出?如果我將==替換爲!=,我將獲得Good work.. keep it up!輸出。

有人可以向我解釋這個嗎?

+1

整數4的值不是字符串4'A = = 4和b == 7'將按預期工作 –

回答

1

取下報價跡象:

if a == 4 and b == 7: 

報價給出,當你想當作一個字符串整數或浮點數確實需要報價

相關問題