Python名称错误:未定义名称“hello”

Python名称错误:未定义名称“hello”,python,nameerror,Python,Nameerror,在Python 3.0中,当我尝试使用任何可能的输入字符串执行以下代码时,我遇到一个NameError: def onePerLine(str): for i in str: print(i) word=input("Enter a phrase or word: ") onePerLine(word) 错误如下: Enter a phrase or word: hello Traceback (most recent call last):File"C:\User

在Python 3.0中,当我尝试使用任何可能的输入字符串执行以下代码时,我遇到一个NameError:

def onePerLine(str):
    for i in str:
        print(i)

word=input("Enter a phrase or word: ")
onePerLine(word)
错误如下:

Enter a phrase or word: hello

Traceback (most recent call last):File"C:\Users\R\Documents\Python30\func2.py",line 5, in <module> word=input("Enter a phrase or word: ")

File "<string>", line 1, in <module>

NameError: name 'hello' is not defined 
如何修复此问题并使代码运行?
PS:我是python和一般编程的新手。任何协助都将不胜感激

您使用的是Python 2,因此需要使用原始输入


您使用的是Python2,因此需要使用原始输入


您使用的是Python2,需要使用原始输入,而不是对字符串求值并将其假定为变量名

输入[提示]

相当于evalraw_inputprompt

考虑使用raw_输入函数进行用户的一般输入


您使用的是Python2,需要使用原始输入,而不是对字符串求值并将其假定为变量名

输入[提示]

相当于evalraw_inputprompt

考虑使用raw_输入函数进行用户的一般输入

>>> x = input('')
hello

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    x = input('')
  File "<string>", line 1, in <module>
NameError: name 'hello' is not defined
>>> x = raw_input('')
hello
>>> x
'hello'