[英]When string will be output with double quotes?and when with single quotes?by %r
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."
)
str.__repr__
更喜欢单引号,除非字符串包含单引号且没有双引号,在这种情况下它使用双引号。
Just use format()
function, don't care %r
,single,double,triple quotes.只需使用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."))
Output:输出:
>>>
I had this thing. That you could type up right. But it didn't sing. so I said goodnight.
>>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.