Python2中input()raw_input()和Python3中input()
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python2中input()raw_input()和Python3中input()相关的知识,希望对你有一定的参考价值。
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = input("please input your name: ")
please input your name: Aelx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name ‘Aelx‘ is not defined
>>> a = input("Please input your name: ")
Please input your name: "Alex"
>>> a
‘Alex‘
>>> b = input("Please input your favorite number: ")
Please input your favorite number: 6
>>> b
6
>>> a = raw_input("Please input your name: ")
Please input your name: geng
>>> a
‘geng‘
>>> b = raw_input("please input your favorite number: ")
please input your favorite number: 4
>>> b
‘4‘
[email protected]:~$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = input("Please input your name: ")
Please input your name: Alex is SB
>>> b = input("Please input your lucky num: ")
Please input your lucky num: 5
>>> b
‘5‘
以上是关于Python2中input()raw_input()和Python3中input()的主要内容,如果未能解决你的问题,请参考以下文章
python-day7--%s与%d的使用,python2中的input及raw_input
Python2input和raw_input和区别和Python3input的区别