python2.x中raw_input()和python3.x中的input()的区别讲解
程序员文章站
2024-01-13 10:43:22
跟着书敲代码的时候突然发现运行raw_input()函数一直报错
Traceback (most recent call last):
File "C:\...
跟着书敲代码的时候突然发现运行raw_input()函数一直报错
Traceback (most recent call last): File "C:\Users\Desktop\python\name.py", line 1, in name=raw_input("what's your name?"+"\n") NameError: name 'raw_input' is not defined
不知为何(我的Python版本是3.6.3),后来查看了文档才知道原来Python2.X版本中存在raw_input()和input()两个函数,但是
Python3.X版本中认为raw_input()是冗余函数就将其作为垃圾扔掉了,因此在运行Python3.X版本时需要将所有的raw_input()替换为input()才能执行。
值得注意的是在Python3.X版本中,input()函数接收所有输入,并默认将所有的输入都看作字符串来处理,返回字符串类型。
以下是修改之后的代码:
name=input("what's your name?"+"\n") print("hello "+name) == RESTART: C:\Users\Desktop\python\name.py == what's your name? helloworld hello helloworld
上一篇: HTML Tag input onclick 可用的功能大全
下一篇: 解决高度塌陷问题
推荐阅读
-
python2.x中raw_input()和python3.x中的input()的区别讲解
-
jquery中:input和input的区别分析_jquery
-
实例讲解Lua中pair和ipair的区别
-
Mybatis下动态sql中##和$$的区别讲解
-
Java中Connection timed out和Connection refused的区别讲解
-
Python中input和raw_input的一点区别
-
Python中input和raw_input的一点区别
-
Python中extend和append的区别讲解
-
SQL2005中char nchar varchar nvarchar数据类型的区别和使用环境讲解
-
Shell中exit和return的区别讲解