名称未定义错误

Ser*_*gei 1 python string

我很清楚这是一个noob问题,但我似乎无法找到解决方案,我对编程很新,但渴望学习.我正在浏览python中的第一个google clases,这是我得到的错误.

def both_ends(s):
  print s[0:2], s[3:5]
  return

x = input('...: ')
both_ends(x)

sergei@sergei-MS-7253:~/Desktop/p2$ python test2.py
...: haloj
Traceback (most recent call last):
  File "test2.py", line 10, in <module>
    x = input('...: ')
  File "<string>", line 1, in <module>
NameError: name 'haloj' is not defined
Run Code Online (Sandbox Code Playgroud)

请解释一下问题所在.

谢谢

Cor*_*ell 5

在Python 2中,input()接受一个应该立即执行的字符串.如果要将给定输入保存为字符串(您的意图),请使用raw_input().