我可以在三引号字符串的开头添加其他引号,但不能添加到结尾.这是为什么?这段代码:
print(""""
String that starts with quadruple quotes and ends with triple quotes
""")
Run Code Online (Sandbox Code Playgroud)
生成此输出:
"
String that starts with quadruple quotes and ends with triple quotes
Run Code Online (Sandbox Code Playgroud)
但是这个代码块不起作用:
print(""""
String that starts with quadruple quotes and ends with quadruple quotes
"""")
Run Code Online (Sandbox Code Playgroud)
它会产生以下错误:
File "example.py", line 3
"""")
^
SyntaxError: EOL while scanning string literal
Run Code Online (Sandbox Code Playgroud)
我不需要使用四重引用字符串,但我很好奇为什么Python不会让我这样做.谁能帮我理解?