Python中关于input和raw_input的比较


本文摘自php中文网,作者黄舟,侵删。

这篇文章主要介绍了Python中input与raw_input 之间的比较的相关资料,通过本文希望能帮助到大家,对于他们之间的使用方法和区别,需要的朋友可以参考下

Python中input与raw_input 之间的比较

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


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

#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

>>>

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

以上就是Python中关于input和raw_input的比较的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

Python一键搭建http服务器的方法

认识Python对象自省机制

Python中(urlparse)模板的使用详解

Python变量与赋值的图文详解

ubuntu怎么安装Python

Python爬虫防止ip被封的方法

非常实用的Python小技巧总结

Python range函数怎么用

Python中socket实现udp通信的介绍(附代码)

Python使用代理ip访问网站

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...