如何在代码中打破一个长的字符串字符串并使字符串与其余代码一起缩进?PEP 8对此案例没有任何示例.
正确的ouptut但奇怪的缩进:
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
Run Code Online (Sandbox Code Playgroud)
输出错误,但在代码中看起来更好:
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
Run Code Online (Sandbox Code Playgroud)
哇,快答案很多.谢谢!
Noa*_*ing 30
相邻的字符串在编译时连接在一起:
if True:
print ("this is the first line of a very long string"
" this is the second line")
Run Code Online (Sandbox Code Playgroud)
输出:
this is the first line of a very long string this is the second line
Run Code Online (Sandbox Code Playgroud)
if True:
print "long test long test long test long test long"\
"test long test long test long test long test long test"
Run Code Online (Sandbox Code Playgroud)