我可以往三引号字符串的开头添加额外的引号,但无法在结尾处添加。为什么会这样?以下是代码块:
print(""""
String that starts with quadruple quotes and ends with triple quotes
""")
生成以下输出:
"
String that starts with quadruple quotes and ends with triple quotes
然而这段代码无法正常工作:
print(""""
String that starts with quadruple quotes and ends with quadruple quotes
"""")
它会产生以下错误:
File "example.py", line 3
"""")
^
SyntaxError: EOL while scanning string literal
我从未需要使用四个引号的字符串,但我很好奇为什么Python不允许我这样做。有人能帮助我理解吗?
""""
结尾处的第一个"
作为值的一部分,而不是作为结束字符串的分隔符的一部分? - Martijn Pieters