相关疑难解决方法(0)

如何在Python中进行换行(换行)?

我有一长串代码,我希望在多行之间分解.我使用什么,语法是什么?

例如,添加一串字符串,

e = 'a' + 'b' + 'c' + 'd'
Run Code Online (Sandbox Code Playgroud)

并将它分成两行:

e = 'a' + 'b' +
    'c' + 'd'
Run Code Online (Sandbox Code Playgroud)

python syntax line-breaks long-lines

979
推荐指数
9
解决办法
144万
查看次数

如何编写符合PEP8的非常长的字符串并阻止E501

由于PEP8建议保持低于你的python程序的80列规则,我怎么能遵守长字符串,即

s = "this is my really, really, really, really, really, really, really long string that I'd like to shorten."
Run Code Online (Sandbox Code Playgroud)

我将如何将其扩展到以下行,即

s = "this is my really, really, really, really, really, really" + 
    "really long string that I'd like to shorten."
Run Code Online (Sandbox Code Playgroud)

python string pep8

182
推荐指数
5
解决办法
6万
查看次数

Python样式 - 用字符串继续行?

在尝试遵守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)

python coding-style

148
推荐指数
4
解决办法
11万
查看次数

python:我应该怎么写很长的代码行?

如果我有一个很长的代码行,是否可以在下一行继续它,例如:

 url='http://chart.apis.google.com/chart?chxl=1:|0|10|100|1,000|10,000|'
+ '100,000|1,000,000&chxp=1,0&chxr=0,0,' +
      max(freq) + '300|1,0,3&chxs=0,676767,13.5,0,l,676767|1,676767,13.5,0,l,676767&chxt=y,x&chbh=a,1,0&chs=640x465&cht=bvs&chco=A2C180&chds=0,300&chd=t:'
Run Code Online (Sandbox Code Playgroud)

python pep8

13
推荐指数
2
解决办法
1万
查看次数

标签 统计

python ×4

pep8 ×2

coding-style ×1

line-breaks ×1

long-lines ×1

string ×1

syntax ×1