-4
我想這個簡單的Python程序:錯誤在Python程序
x == 3 print x
,但我得到這個錯誤:
Traceback (most recent call last): File "", line 1, in NameError: name 'x' is not defined
爲什麼?
我想這個簡單的Python程序:錯誤在Python程序
x == 3 print x
,但我得到這個錯誤:
Traceback (most recent call last): File "", line 1, in NameError: name 'x' is not defined
爲什麼?
==
僅用於比較,不指定。你在問x是否等於3,但還沒有告訴Python x是什麼。
你想這樣的:
x = 3
print x
'X == 3' - >'X = 3'。 – 2013-02-11 18:30:15
你正在比較x和x == 3而不是聲明它。嘗試x = 3 – BorrajaX 2013-02-11 18:30:29
@Phil Frost:您的賬戶被破解或有什麼? http://stackoverflow.com/users/1574959/phil-frost?tab=answers&sort=votes – BorrajaX 2013-02-11 18:32:39