Python注释的长度

问题描述 投票:0回答:1

[当我想为代码编写解释性注释时,但行很长,分割注释的最佳方法是什么?

最好通过在其后进行如下新评论来继续评论

schedule.pop(0)                             # reads the file of programs as a list and pops the two first lines

list_of_program = []                        # creates an empty list where the programs and their attributes current_channel = ""          
# stores the channels from the for-loop

for program_line in schedule:               # builds the list from a for-loop by splitting the lines in the list
    if program_line[0] == "-":              # to get each attribute necessary to identify the program
        continue

或者我应该以其他方式分开?

python python-3.x pep8
1个回答
0
投票

在Python文档中,您可以使用“”“进行多行注释。但是,这种用法通常是出于文档目的而创建的。

示例用法:

"""
This is multi line

commenting

"""

而且pep-8格式对于性能也很重要。

Pep-8格式指南:https://www.python.org/dev/peps/pep-0008/

© www.soinside.com 2019 - 2024. All rights reserved.