这不起作用:
something = \
line_of_code * \ # Comment
another_line_of_code * \ # Comment
and_another_one * \ # Comment
etc
这也不:
something = \
# Comment \
line_of_code * \
# Comment \
another_line_of_code * ...
这也不:
something = \
''' Comment ''' \
line_of_code * \
''' Comment ''' \
another_line_of_code * ...
有没有办法将代码中的注释分成多行?
这样做:
a, b, c, d = range(1, 5)
result = (
# First is 1
a *
# Then goes 2, result is 2 now
b *
# And then 3, result is 6
c *
# And 4, result should be 24
d
)
实际上,根据 PEP8当将某些内容分成多行时,括号优于斜杠:
换行长行的首选方法是在圆括号、方括号和大括号内使用 Python 的隐式续行。通过将表达式括在括号中,可以将长行分成多行。应优先使用这些内容而不是使用反斜杠来继续行。
在你的情况下,它还允许发表评论。
这是一个证明,它有效:http://ideone.com/FlccUJ
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)