%s 用str()方法处理对象

%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

最新文章

  1. php-(/usr/local/php)安装编译选项
  2. DOM树操作
  3. Java api 入门教程 之 JAVA的IO处理
  4. Meaningful Use 中与HL7相关的消息及医疗文档
  5. Debian系统网卡调试出问题,无线网卡提示device not managed如何解决?
  6. FZU 2215 Simple Polynomial Problem(简单多项式问题)
  7. My集合框架第三弹 AVL树
  8. Windows7下32位IE异常不能打开解决方法
  9. B桥接模式ridge
  10. Codeforces 719B Anatoly and Cockroaches
  11. win10 sdk 是否向下兼容
  12. 书写规范的javaScript
  13. Linux下JNA 调用 so 库
  14. [模板][P3808]AC自动机(简单版)
  15. hdu-4507 吉哥系列故事——恨7不成妻 数位DP 状态转移分析/极限取模
  16. Oracle中如何停止正在执行SQL语句
  17. OS-96
  18. CMake: Could NOT find PkgConfig
  19. UVA11324_The Largest Clique
  20. linux下如何查看所有的用户和组信息?

热门文章

  1. CXF、Spring整合的SOAP Web Service服务端
  2. XML复习笔记(复习资料为菜鸟教程里的XML教程)
  3. Studio 3T for MongoDB连接51.212复制集
  4. 利用CoreTelephony获取用户当前网络状态(判断2G,3G,4G)
  5. HDU3085 Nightmare Ⅱ —— 双向BFS + 曼哈顿距离
  6. html5--6-50 动画效果-变形
  7. 计算机科学 —— 时间戳(timestamp)
  8. Apostrophe not preceded by \
  9. 【AC自动机&&Trie图】积累
  10. jsp 验证码