出於某種原因,我得到一個NameError
異常升高當我嘗試執行此代碼:你將如何退出Python中的字符串文字循環?
while True:
fileString = input("Enter your command: ")
print(fileString)
if fileString is "end":
break
else:
print("\nSomething went wrong! Please try again.")
continue
print("The program will now shut down.")
我想打破循環時,在輸入輸入「結束」。
你使用的是什麼版本的Python? – njzk2
** tl; dr **不要使用'is'關鍵字作爲初學者。這不是你想要的機器人。使用== == – smci
大家都在急着回答,3個不同的人似乎都錯過了NameError。 – user2357112