str与repr,input与raw_input比较
来源:互联网 发布:mac队装备 编辑:程序博客网 时间:2024/06/08 02:11
一.str与repr比较:
1.共同点:str和repr都是一个函数。
2.不同点:str:此函数将把参数值转换成合理形式的字符串;
repr:此函数则会创建一个字符串,然后以合法的python表达式形式来表示值;
3.实例str:
>>> print str("hello world")
hello world
>>> print str(1000L) #将long参数转换成字符串
1000
4.实例repr:
>>> print repr("hello world")
'hello world'
>>> print repr(1000L) #重新创建一个字符串,以合法的python表达式输出
1000L
>>> temp =42L
>>> print "the temperature is " +repr(temp)
the temperature is 42L
二.input与raw_input比较:
1.input函数:需要以合法的python表达式形式输入
如:
>>> name = input ("what is your name ?")
what is your name ?
当输入为数值型:3时,通过;当输入为字符型:lucy时,抱错:
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
name = input ("what is your name ?")
File "<string>", line 1, in <module>
NameError: name 'lucy' is not defined
因为字符型的合法表达式应为:'lucy',如果输入'lucy'或者"lucy"则通过
2.raw_input函数:将会把所有的输入当原始数据处理
如:
>>> name = raw_input ("what is your name ?")
what is your name ?lucy
>>>
此时直接输入lucy就不会抱错。
- str与repr,input与raw_input比较
- raw_input与input的比较
- repr()与str()
- python学习:input与raw_input比较
- str()与repr()的区别
- python中的repr与str
- python中str与repr
- str与repr的区别
- input()与raw_input()
- raw_input() 与 input()
- input()与raw_input()区别
- raw_input() 与input()
- input 与 raw_input
- python input()与raw_input()
- raw_input 与 input
- raw_input() 与 input() Python
- python input()与raw_input()
- python input()与raw_input()
- The Core MongoDB Operations with Native Java Driver
- mahout配置
- Mysql 连接(inner join,默认的就是内连接)、外连接(left join,right join)
- 关于在线编辑器Kindeditor上传图片报错的问题:没有权限
- mysql安装配置
- str与repr,input与raw_input比较
- /proc/[pid]/stat 文件解释
- 尝试安装Chrome OS的新版本 Vanilla & 安装之后U盘遇到的问题解决
- css+js的选项卡效果
- gprof使用
- OpenCart之联系我们contact us页面提交时邮件错误
- hadoop2.2.0单机安装(记录)
- IE7 float:right 时元素换行 的bug解决方法
- 怎样让自己的程序进程不让别人强行关闭掉