首页 > 代码库 > Python2中input()、raw_input()和Python3中input()
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‘
zhuzhu@zhuzhu-K53SJ:~$ 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()