2014-03-25 72 views
0

我有一個「if」語句,但它只能識別它作爲變量等於什麼。 真的不知道該如何解釋得很好,但這裏有一個例子只能識別變量的Python

a = input("Hello! What is your name?")               
if a == Gabe_Newell :                   
    print ("Hello, Gaben!")                 
+0

你能解釋得更清楚嗎?我不明白。 – GhostGambler

回答

4

你有一個字符串進行比較:

a = input("Hello! What is your name?") 
if a == "Gabe_Newell": 
    print ("Hello, Gaben!") 

這個代碼適用於python3,如果使用python2,寫:

a = raw_input("Hello! What is your name?") 
if a == "Gabe_Newell": 
    print ("Hello, Gaben!") 

我假設你想說Hello, Gaben當用戶輸入Gabe_Nawell

+0

非常感謝你 – user3462057