相关疑难解决方法(0)

为什么在Python 3中,四重引号会产生语法错误?

我可以在三引号字符串的开头添加其他引号,但不能添加到结尾.这是为什么?这段代码:

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不会让我这样做.谁能帮我理解?

python string python-3.x

3
推荐指数
1
解决办法
1089
查看次数

标签 统计

python ×1

python-3.x ×1

string ×1