Python中input与raw_input 之间的比较

Python中input与raw_input 之间的比较

input和raw_input均可以接收输入,其差别如下所示:

#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>",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
>>>

因此,一般情况下应尽可能的使用raw_input。

以上就是 Python中input与raw_input 之间的比较,有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持

相关文章

在前一篇博客中我们介绍了加侧旋的乒乓球弧圈技术的模拟,本...
在近期conda的版本更新中,有可能会删除路径下的_sysconfigd...
本文主要展示了一些lambda表达式的使用示例,通过这些示例,...
本文通过对比Jax和Numpy计算Normalized Hamming Distance的过...
我们知道GPU加速在可并行化程度比较高的算法中,能够发挥出比...
Numpy这个库在Python编程中非常的常用,不仅在性能上补足了P...