python程序格式化字符%r输出问题?

0

python中字符格式%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."
)
输出结果:'I had this thing.' 'That you could type up right.' "But it didn't sing." 'So I
said goodnight.'
输出发现第3个是双引号字符串,其他都是单引号字符。
请帮忙解释下,谢谢!
关注者
1
被浏览
 
已邀请:
2

- 取是能力,舍是境界 2017-02-08 回答

这个很好解释,从编程来说字符串表示两种方式,双引号或者单引号。内容中有单引号了,所以输出结果就外面用双引号表示字符串,内容单引号正常显示,而没有去转译。你输出下下面的语句应该就能理解了。
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."
)


 

要回复问题请先登录注册