Discuss / Python / name=input()输出的时候报错了

name=input()输出的时候报错了

Topic source

一个奇怪的现象,我写下了一个input.py 内容如下:

#!/usr/bin/env python3

name=input("please enter your name:")
print("hello,",name)

执行的时候却是:

$ python input.py
please enter your name:ghf
Traceback (most recent call last):
  File "input.py", line 3, in <module>
    name=input("please enter your name:")
  File "<string>", line 1, in <module>
NameError: name 'ghf' is not defined

为什么会这样呢? 换成

name=raw_input("please enter your name:")

就可以

高清楚了。

应该用的python3,而我用了python2


  • 1

Reply