raw_input在Python
2中使用来获取字符串,
input在Python
2中等效于
eval(raw_input)。
>>> type(raw_input())23<type 'str'>>>> type(input())12<type 'int'>
因此,当您输入类似的内容时
n,
input它会认为您正在寻找一个名为的变量
n:
>>> input()nTraceback (most recent call last): File "<ipython-input-30-5c7a218085ef>", line 1, in <module> type(input()) File "<string>", line 1, in <module>NameError: name 'n' is not defined
raw_input工作良好:
>>> raw_input()n'n'
帮助
raw_input:
>>> print raw_input.__doc__raw_input([prompt]) -> stringRead a string from standard input. The trailing newline is stripped.If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.On Unix, GNU readline is used if enabled. The prompt string, if given,is printed without a trailing newline before reading.
帮助
input:
>>> print input.__doc__input([prompt]) -> valueEquivalent to eval(raw_input(prompt)).



