Python 长字符串的修饰转义

Python cosmetic escapes for long string

我有一些愚蠢的事情让我很烦。使用 flake8 linter,他们显然喜欢短线,如果我 运行 如下所示的字符串在下一行继续:

print('\nWe interrupt this program to annoy you and make things \
          generally more irritating.\n')

这是打印的内容:

We interrupt this program to annoy you and make things               generally more irritating.

在打印输出之间没有大 space 的情况下继续一行代码的正确方法是什么?

这个有效:

print("\nWe interrupt this program to annoy you and make things "
      "generally more irritating.\n")

您不需要任何续集。只需将两个字符串放在一起,中间没有任何内容,Python 解析器就会知道连接它们的意思

这叫做string literal concatenation

我建议将长字符串放入一个变量中并打印该变量。

message = ("We interrupt this program to annoy you and make things "
           "generally more irritating.\n")
print(message)

Python 自动处理字符串延续,因为它包含在括号中。