我正在学习《笨办法学Python》,在进行以下操作时:
formatter = "%r %r %r %r"
print formatter % (
"I had this thing.",
"That you could up right.",
"But it didn't sing.",
"So I said goodnight"
)
输出结果为:
'I had this thing.' 'That you could up right.' "But it didn't sing." 'So I said goodnight'
但我不确定为什么第三个字符串有双引号。
'But it didn''t sing'
是有效的语法,但它并不符合我们的要求,因为Python将相邻的字符串文字视为单个字符串。如果字符串文字之间有空格,也会发生这种情况。 - PM 2Ring