%r
是repr
%s
是str
比如\x27是单引号
>>> print '%r'%'\x27' # 带括号的单引号
"'"
>>> print '%s'%'\x27' # 纯单引号
'
>>> class Example(object):
... __repr__ = lambda cls: '<Demo>(repr)'
... __str__ = lambda cls: '<Demo>(str)'
...
>>> example = Example()
>>> print '%s'%example
<Demo>(str)
>>> print '%r'%example
<Demo>(repr)
s意义是字符串
r意义是使用repr,而不是str
%r 用来做 debug 比较好,因为它会显示变量的原始数据(raw data),而其它的符号则是用来向用户显示输出的。