我試圖打印出真如果有這樣的字母/單詞和假如果沒有,但無論我鍵入,它總是如此。Python的真假,並在
phr1= raw_input("Enter a phrase or paragraph, and this will check if you have those letters/word in ur paragraph: ")
print "You entered: "+phr1
phr2= raw_input("Check if a word/letter exists in the paragraph: ")
phr2 in phr1
if True:
print "true"
elif False:
print "false"
input("Press enter")
當我運行代碼:
Enter a phrase or paragraph, and this will check if you have those letters/word in ur paragraph:
hello world
You entered: hello world
Check if a word/letter exists in the paragraph: g
true
Press enter
這個可能,G這麼想的是如何存在的,爲什麼它說出來呢?
你永遠不會知道phr1中phr2的值並將它存儲在任何地方,所以下面的語句不知道檢查是否通過了 – nbrooks