如何在我的代码中打断一个长的线性字符串并使该字符串与其余代码保持缩进? PEP 8没有任何关于这种情况的例子。
正确的输出但奇怪的缩进:
if True:
print "long test long test long test long test long \
test long test long test long test long test long test"
>>> long test long test long test long test long test long test long test long test long test long test
输出不佳,但在代码中看起来更好:
if True:
print "long test long test long test long test long \
test long test long test long test long test long test"
>>> long test long test long test long test long test long test long test long test long test long test
哇,很多快速的答案。谢谢!
请您参考如下方法:
相邻的字符串在编译时连接起来:
if True:
print ("this is the first line of a very long string"
" this is the second line")
输出:
this is the first line of a very long string this is the second line
