raw_input()和input()的区别
1.在python2.7中,我们看一下代码
raw_input:
C:\Users\muxiao>py -2 Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit ( AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> a = raw_input(':') :123 >>> a '123' >>> a = raw_input(':') :"abcd" >>> a '"abcd"' >>> a = raw_input(':') :abcd >>> a 'abcd' >>> a = raw_input(':') :[1,2,3] >>> a '[1,2,3]' >>>
input:
C:\Users\muxiao>py -2
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (
AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a = input(':')
:123
>>> a
123
>>> a = input(':')
:'abcd'
>>> a
'abcd'
>>> a = input(':')
:[1,2,3]
>>> a
[1, 2, 3]
>>> a = input(':')
:abdc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'abdc' is not defined
python3中,只有input功能和python2中的raw_input一样

浙公网安备 33010602011771号