Python 格式符大聚會之%r

一、%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

相關文章
相關標籤/搜索