Skip to main content
 首页 » 编程设计

获取值时出现 Python 错误

2025年05月04日10kerrycode

我使用的是 Python 2.7.3 版。当我尝试运行以下代码时,出现错误,

>>> value = input("get value: ") 
 
    get value: hello 
 
    Traceback (most recent call last): 
 
    File "<stdin>", line 1, in <module> 
 
    File "<string>", line 1, in <module> 
 
    NameError: name 'hello' is not defined 

请您参考如下方法:

当传递字符串时,使用 " 或将 hello 放在 " 中。"hello" 类似这样的东西。

或

只需使用raw_input()