Python %s和%r的区别
2024-10-21 13:24:17
%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
最新文章
- php-(/usr/local/php)安装编译选项
- DOM树操作
- Java api 入门教程 之 JAVA的IO处理
- Meaningful Use 中与HL7相关的消息及医疗文档
- Debian系统网卡调试出问题,无线网卡提示device not managed如何解决?
- FZU 2215 Simple Polynomial Problem(简单多项式问题)
- My集合框架第三弹 AVL树
- Windows7下32位IE异常不能打开解决方法
- B桥接模式ridge
- Codeforces 719B Anatoly and Cockroaches
- win10 sdk 是否向下兼容
- 书写规范的javaScript
- Linux下JNA 调用 so 库
- [模板][P3808]AC自动机(简单版)
- hdu-4507 吉哥系列故事——恨7不成妻 数位DP 状态转移分析/极限取模
- Oracle中如何停止正在执行SQL语句
- OS-96
- CMake: Could NOT find PkgConfig
- UVA11324_The Largest Clique
- linux下如何查看所有的用户和组信息?
热门文章
- CXF、Spring整合的SOAP Web Service服务端
- XML复习笔记(复习资料为菜鸟教程里的XML教程)
- Studio 3T for MongoDB连接51.212复制集
- 利用CoreTelephony获取用户当前网络状态(判断2G,3G,4G)
- HDU3085 Nightmare Ⅱ —— 双向BFS + 曼哈顿距离
- html5--6-50 动画效果-变形
- 计算机科学 —— 时间戳(timestamp)
- Apostrophe not preceded by \
- 【AC自动机&;&;Trie图】积累
- jsp 验证码