我试图在python中将多行字符串与单行连接,并且它给我一个无效的语法错误。
.hpp
答案 0 :(得分:2)
无需使用+
运算符来连接您希望通过多行分布的字符串,以获得更好的可读性。做这样的事情:
s = (
"my very long string"
"that spans multiple lines"
)
解析器将正确处理此问题并且 是Python语法的一部分(String Literal Concatentation。将更大的字符串转换为这样的代码序列通常会更具可读性。< / p>
有关详细信息,请参阅Strings上的Python文档:
当您想要打破长字符串时,此功能特别有用:
>>> text = ('Put several strings within parentheses '
'to have them joined together.')
>>> text
'Put several strings within parentheses to have them joined together.'