我有些愚蠢的东西使我讨厌。如果我运行如下所示的字符串以继续下一行,则使用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.
在没有打印输出之间大空间的情况下继续执行一行代码的正确方法是什么?
答案 0 :(得分:2)
这有效:
print("\nWe interrupt this program to annoy you and make things "
"generally more irritating.\n")
您不需要任何继续。只需将两个字符串放在一起,中间没有任何内容,Python解析器就会知道将它们连接在一起的意思
答案 1 :(得分:2)
我建议将长字符串放入变量中并打印该变量。
message = ("We interrupt this program to annoy you and make things "
"generally more irritating.\n")
print(message)
Python自动处理字符串连续性,因为它包含在括号中。