在尝试遵守python样式规则时,我将编辑器设置为最多79列.
在PEP中,它建议在括号,括号和括号内使用python隐含的延续.但是,当我达到col限制时处理字符串时,它会有点奇怪.
例如,尝试使用多行
mystr = """Why, hello there
wonderful stackoverflow people!"""
Run Code Online (Sandbox Code Playgroud)
将返回
"Why, hello there\nwonderful stackoverflow people!"
Run Code Online (Sandbox Code Playgroud)
这有效:
mystr = "Why, hello there \
wonderful stackoverflow people!"
Run Code Online (Sandbox Code Playgroud)
因为它返回:
"Why, hello there wonderful stackoverflow people!"
Run Code Online (Sandbox Code Playgroud)
但是,当语句缩进几个块时,这看起来很奇怪:
do stuff:
and more stuff:
and even some more stuff:
mystr = "Why, hello there \
wonderful stackoverflow people!"
Run Code Online (Sandbox Code Playgroud)
如果您尝试缩进第二行:
do stuff:
and more stuff:
and even some more stuff:
mystr = "Why, hello there \
wonderful stackoverflow people!"
Run Code Online (Sandbox Code Playgroud)
你的字符串最终为:
"Why, hello there wonderful stackoverflow …Run Code Online (Sandbox Code Playgroud)