社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

Python字符串输入提供错误,除非使用引号

Mohammad Rahman • 6 年前 • 2191 次点击  

我以为 input 方法将获取任何数字或字符串输入并将其打印出来。但是为了 string 除非 在引用中。为什么?

string input

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54905
文章 [ 2 ]  |  最新文章 6 年前
Kenta Nomoto
Reply   •   1 楼
Kenta Nomoto    6 年前

在Python2上,需要用“”引用输入

不过,似乎有多种解决方案:

input() error - NameError: name '...' is not defined

saeed foroughi
Reply   •   2 楼
saeed foroughi    6 年前

在Python2.7中, input() raw_input() 将所有输入视为字符串(不需要引号)。

在Python3.x中,Python2.7 原始输入() 方法已重命名 以及Python 2.7 功能被替换为 eval(input())

原始输入() 在Python2.7中或切换到Python3.x