123*_*213 0 python comments pep8 python-2.7 continuation
我有这个代码块我想评论,但内联注释不起作用.我不确定PEP8指南适用于何处.建议吗?
if next_qi < qi + lcs_len \ # If the next qLCS overlaps
and next_ri < ri + lcs_len \ # If the next rLCS start overlaps
and next_ri + lcs_len > ri: # If the next rLCS end overlaps
del candidate_lcs[qi] # Delete dupilicate LCS.
Run Code Online (Sandbox Code Playgroud)
在Python中,\在行继续符之后没有任何东西可以出现.
但是,如果将条件置于括号中,则可以执行所需操作:
if (next_qi < qi + lcs_len # If the next qLCS overlaps
and next_ri < ri + lcs_len # If the next rLCS start overlaps
and next_ri + lcs_len > ri): # If the next rLCS end overlaps
del candidate_lcs[qi] # Delete dupilicate LCS.
Run Code Online (Sandbox Code Playgroud)
以下是演示:
>>> if (1 == 1 # cond 1
... and 2 == 2 # cond 2
... and 3 == 3): # cond 3
... print True
...
True
>>>
Run Code Online (Sandbox Code Playgroud)
该相关PEP 8方针是:
包装长行的首选方法是在括号,括号和括号内使用Python隐含的行继续.通过将表达式包装在括号中,可以在多行中分割长行.这些应该优先使用反斜杠来继续行.