Python %s和%r的区别
2015-04-09 10:31
288 查看
%s 用str()方法处理对象
%r 用rper()方法处理对象,打印时能够重现它所代表的对象(rper() unambiguously recreate the object it represents)
例一:
例二:
例三:
出处:
http://stackoverflow.com/questions/6005159/when-to-use-r-instead-of-s-in-python http://blog.csdn.net/wusuopubupt/article/details/23678291
%r 用rper()方法处理对象,打印时能够重现它所代表的对象(rper() unambiguously recreate the object it represents)
例一:
>>> print("Today is %s" % a) Today is sunday >>> print("Today is %r" % a) Today is 'sunday'
例二:
>>> content = "What wrong with you, %s" % "Tom" >>> print("Today is sunday, %s" % content) Today is sunday, What wrong with you, Tom >>> print("Today is sunday, %r" % content) Today is sunday, 'What wrong with you, Tom'
例三:
>>> import datetime >>> d = datetime.date.today() >>> print("%s" % d) 2015-04-01 >>> print("%r" % d) datetime.date(2015, 4, 1)
出处:
http://stackoverflow.com/questions/6005159/when-to-use-r-instead-of-s-in-python http://blog.csdn.net/wusuopubupt/article/details/23678291
相关文章推荐
- Python %s和%r的区别
- python 中的%s 和%r的区别
- Python中%s和%r的区别
- python:单引号,双引号和三引号的区别
- Python3.x和Python2.x的区别
- 讨论python的数据类型的区别
- Python3.x和Python2.x的区别
- python string和PyQt的QString的区别
- shell+sed+awk和perl和python的区别
- Python的ASCII, GB2312, Unicode , UTF-8区别
- Python里method和function的区别
- Python调用C的DLL和VC调用有什么区别?
- Python的ASCII, GB2312, Unicode , UTF-8区别
- python3 与 python2区别
- Python的ASCII, GB2312, Unicode , UTF-8区别
- Python中classmethod, staticmethod和普通method的区别
- Python 3 与Python 2的区别
- Python中Range和XRange的区别
- python_20100901_元组列表字典的一点区别
- python中元组与列表的区别