str vs repr
来源:互联网 发布:手机淘宝搜索排名规则 编辑:程序博客网 时间:2024/05/22 07:41
repr()是将一个对象转成字符串显示,注意只是显示用,有些对象转成字符串没有直接的意思。如list,dict使用str()是无效的,但使用repr可以,这是为了看它们都有哪些值,为了显示之用。
Some examples:
>>> s = 'Hello, world.'
>>> str(s)
'Hello, world.'
>>> repr(s)
"'Hello, world.'"
>>> str(0.1)
'0.1'
>>> repr(0.1)
'0.10000000000000001'
>>> x = 10 * 3.25
>>> y = 200 * 200
>>> s = 'The value of x is ' + repr(x) + ', and y is ' + repr(y) + '...'
>>> print s
The value of x is 32.5, and y is 40000...
>>> # The repr() of a string adds string quotes and backslashes:
... hello = 'hello, world\n'
>>> hellos = repr(hello)
>>> print hellos
'hello, world\n'
>>> # The argument to repr() may be any Python object:
... repr((x, y, ('spam', 'eggs')))
"(32.5, 40000, ('spam', 'eggs'))"
>>> # reverse quotes are convenient in interactive sessions:
... `x, y, ('spam', 'eggs')`
"(32.5, 40000, ('spam', 'eggs'))"
- str vs repr
- 飘逸的python - str vs. repr
- python-str()和 repr()
- str和repr区别
- Python repr str 函数
- repr()与str()
- str and repr 函数
- python str()/repr()
- python str, repr
- repr,str,和''
- python print str repr pprint
- 字符串表示,str 和 repr
- Python repr() 或str() 函数
- str()与repr()的区别
- python中的repr与str
- Python repr() str() print %r
- str()和repr()的区别
- Python的str()和repr()
- PHP 字符串长度计算 - strlen() 函数
- 18、从头学Android之BroadcastReceiver
- 那时候母亲的电话打得很勤
- linux no space left on device的解决办法(iNode满导致)
- Js+Jq获取URL参数的集中方法
- str vs repr
- Fedora 20 音视频播放
- Xcode从5.1升级到5.1.1后,重装dyci
- 早教B2C商城SEO分析之收录数据-转自ITSEO老狼
- 无聊写了个抓网页js中链接,当做个笔记
- 17、从头学Android之Service初步二
- 苹果App Store审核指南中文翻译(更新)
- hibernate4按照帮助文档配置了好久没有成功的问题
- 19、从头学Android之Android的数据存储--SharedPreferences