Python 2.6.6 (r266:84292, Aug 9 2016, 06:11:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
区别:
input返回值是int类型
raw_input是字符串类型。
举例说明:
>>>username=input('username: ')
username: albert
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'albert' is not defined
由于input返回值是int类型,所以输入albert时会出错。这时要使用raw_input。
>>> pin = input('PIN code : ')
PIN code : 1234
>>> pin
1234 ----int 类型
>>> pin = raw_input('PIN code : ')
PIN code : 1234
>>> pin
'1234' -----字符串类型
如果有疑问可以欢迎指出,一起讨论