一、%r是一个万能的格式符,它会将后面给的参数原样打印出来this
示例代码orm
# -- coding:utf8 --
#%r是一个万能的格式符,它会将后面给的参数原样打印出来
formatter="%r %r %r %r"
print formatter % (1,2,3,4)
print formatter % ("one","two","three","four")
print formatter % (True,False,False,True)
print formatter % (formatter,formatter,formatter,formatter)
print formatter % (
"I had this thing.",
"That you could type up right.",
"But it didn't sing.",
"So I said goodnight."
)three
二、 将 %r 和 %s 比较一下utf-8
# coding:utf-8it
#%r 打印出来的是你写在脚本里的内容,而 %s 打印的是你应该看到的内容。form
tabby_cat="\tI'm tabbed in."coding
print "%r" %tabby_cat #打印出来 "\tI'm tabbed in."脚本
print "%s" %tabby_cat #打印出来 I'm tabbed in.tab