这是我的测试代码,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