Python2的代码:
>>> name = input("Please input your name:")
Please input your name: "LiCheng"
>>> name
'LiCheng'
>>> name = input("Please input your age:")
Please input your age:26
>>> name
26
>>> raw_name = raw_input("Please input your name:")
Please input your name:Licheng
>>> raw_name
'Licheng'
>>> raw_name = raw_input("Please input your age:")
Please input your age:26
>>> raw_name
'26'
>>> type(raw_name)
<type 'str'>
>>> type(name)
<type 'int'>
>>>
Python3中的代码:
>>> name = input("Please input your name:")
Please input your name: "LiCheng"
>>> name
'LiCheng'
>>> type(name)
<type 'str'>
>>> name = input("Please input your age:")
Please input your age:26
>>> name
26
>>> type(name)
<type 'int'>
>>>
在python2中input()方法,需要使用者明确自己输入的是数字还是字符,字符使用单引号或者双引号。
在python2中的raw_input()方法,不需要区分字符还是数字,系统均默认为字符了。
而在python3中只有input()方法,它和python2中的raw_input()是一样的。