对于标准输入的处理,不同于py3,将所有标准输入均处理为字符串,py2中则严格区分数值跟字符串。
py3:
print(type(input()))
>>12
12
<class 'str'>
py2:
print(type(input()))
>>12
12
<type 'int'>
但是对于py2 input字符串去有所不同:
print(type(input()))
>>asd
Traceback (most recent call last):
File "c:\Users\Stan Pao\Desktop\办公\Python\Test\new.py", line 1, in <module>
print(type(input()))
File "<string>", line 1, in <module>
NameError: name 'asd' is not defined
------------------------------------
py2中的input在输入字符串时需要严格用引号标识出字符串
print(type(input()))
>>‘asd’
'asd'
<type 'str'>
鉴于py2中input()对输入数据类型严格的区分,因此多使用raw_input(),作用同py3中input,全作为字符串输入。
print(type(raw_input()))
12
<type 'str'>
asdf
<type 'str'>