raw_input() 与 input()的不同

text = raw_input("Enter a string:")将用户的输入当作字符串(str),即text是字符串。

num = input("Enter a number:")将用户的输入当作数字(int or float),即num是数字。

测试:

 

>>>text = raw_input("Enter a string:")

Enter a string: hello

>>> print type(text)

输出:<type 'str'>  

>>>num = input("Enter a number:")

Enter a number:12.4

>>>print type(num)

输出:<type 'float'>

 

你可能感兴趣的:(python)