1羊苟、raw_input()函數(shù)
raw_input()將所有輸入作為字符串看待塑陵,不管用戶輸入什么類型的都會轉變成字符串。
>>> y=raw_input("please input:")
??????? please input:abc
>>> y
??????? 'abc'
>>> z=raw_input("please input:")
?????? please input:34
>>> z
?????? '34'
>>> m=raw_input("please input:")
??????? please input:[2,3,1,4]
>>> m
?????? '[2,3,1,4]'
>>> n=raw_input("please input:")
??????? please input:3+2
>>> n
????????? '3+2'
2蜡励、input()函數(shù)
等價于:eval(raw_input( )) 猿妈,eval函數(shù)是將字符串str當成有效Python表達式來求值吹菱,并返回計算結果。 input( )函數(shù)如果要輸入字符串就必須要用引號括起來彭则,否則它會引發(fā)一個 SyntaxError鳍刷。
>>> y=input("please input:")
?????? please input:abc
Traceback (most recent call last): File "",
iny=input("please input:") File "", line 1,
in NameError: name 'abc' is not defined
>>> z=input("please input:")
?????? please input:3
>>> z
??????? 3
>>> m=input("please input:")
??????? please input:3+2
>>> m
???????? 5