Home >Backend Development >Python Tutorial >Python: Detailed explanation of input() and raw_input()
a = input('请输入:') print a
If you enter a string, an error will be reported immediately:
请输入:str Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 1, in <module>
But if you enter an integer, no error will be reported:
请输入:1010
If input
is changed to raw_input
, the keyboard input string can be recorded normally:
a = raw_input('请输入:')print a
请输入:str str
The reason is that, input
can only accept integer input:
a = input('请输入:')print type(a)
请输入:10<type 'int'>
and raw_input
can accept string input:
a = raw_input('请输入:')print type(a)
请输入:str <type 'str'>
The above is the detailed content of Python: Detailed explanation of input() and raw_input(). For more information, please follow other related articles on the PHP Chinese website!