Home > Article > Backend Development > Comparison between input and raw_input in Python
This article mainly introduces the relevant information about the comparison between input and raw_input in Python. Through this article, I hope it can help everyone. For the usage and differences between them, friends who need it can refer to it
Comparison between input and raw_input in Python
Both input and raw_input can receive input, the difference is as follows:
#input假设用户输入的是合法的Python表达式 >>> name = input("what is your name?") what is your name?ZJ Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 1, in <module> NameError: name 'ZJ' is not defined #于是,必须这么使用,输入Python格式的字符串"ZJ" >>> name = input("what is your name?") what is your name? "ZJ" >>> print name ZJ >>> #raw_input会把所有输入当作原始数据(raw data),然后将其放入字符串中 >>> name = raw_input("what is your name?") what is your name?ZJ >>> print name ZJ >>>
Therefore, in general, raw_input should be used as much as possible.
The above is the detailed content of Comparison between input and raw_input in Python. For more information, please follow other related articles on the PHP Chinese website!