所以我正在经历"以艰难的方式学习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'
但我不确定为什么第3个字符串有双字符串.
"a"
并且'a'
是相同的字符串,没有区别.
第三个字符串包含一个撇号,因此它不能表示为'But it didn't sing.'
因为它会在字符串之后结束didn
并引发一个SyntaxError
.
如果要表示带单引号的字符串,可以执行以下操作:
"'"
要么
'\''
双引号相同:
'"'
要么
"\""
如果你有一个带两个引号的字符串,你可以选择一个:
'"\'"
要么
"\"'"