這是我的測試代碼,test.py
:Python字符串解析錯誤
str = input("IP: ")
print(str)
當運行我得到這個錯誤:
➜ PingScript git:(master) ✗ python test.py
IP: 1.1.1.1
Traceback (most recent call last):
File "test.py", line 1, in <module>
str = input("IP: ")
File "<string>", line 1
1.1.1.1
^
SyntaxError: invalid syntax
這隻發生,如果我用1.1.1.1
作爲輸入,而不是如果我使用1.1
作爲輸入,這裏發生了什麼?我試圖用str(str)
解析它,但我仍然得到相同的錯誤。
使用的raw_input'()' –
不要將其命名變量'str'。你期望'str(str)'做什麼? – geoffspear