当前位置: 移动技术网 > IT编程>脚本编程>Python > python2.x中raw_input()和python3.x中的input()的区别讲解

python2.x中raw_input()和python3.x中的input()的区别讲解

2018年02月22日  | 移动技术网IT编程  | 我要评论

长袖礼服裙,娜高假体隆胸多少钱,猎奇窝

跟着书敲代码的时候突然发现运行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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网