formatter = "%r %r %r %r"
print formatter % (
"I had this thing.",
"That you could type up right.",
"But it didn't sing.",
"so I said goodnight."
)
答案 0 :(得分:4)
str.__repr__
更喜欢单引号,除非字符串包含单引号且没有双引号,在这种情况下它使用双引号。
答案 1 :(得分:0)
只需使用format()
功能,不关心%r
,单引号,双引号,三引号。
formatter= "{} {} {} {}"
print ((formatter).format (
"I had this thing.",
"That you could type up right.",
"But it didn't sing.",
"so I said goodnight."))
输出:
>>>
I had this thing. That you could type up right. But it didn't sing. so I said goodnight.
>>>