Python %s和%r的区别
2015-04-01 18:56
477 查看
%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中%r和%s的区别
- %r与%s的区别
- python3 开发面试题(%s和format的区别)5.31
- python中%r和%s的区别
- python中%r和%s的区别
- python中%r和%s的区别
- python %r 和%s的区别
- Python %s和%r的区别
- Python 格式化输出 —— %r 与 %s 的区别(__repr__ 与 __str__)
- python中%s与%r的区别
- python中%s与%r的区别
- Python 版本3和版本2 的字符串格式化区别 ----%s
- Python 格式化字符%r与%s的区别
- python中%r和%s的区别
- python学习笔记1:%r和%s的区别
- Python中%r和%s的区别
- Python的ASCII, GB2312, Unicode , UTF-8区别
- python:单引号,双引号和三引号的区别