What is the proper way to comment functions in Python?

前端 未结 10 1599
情书的邮戳
情书的邮戳 2021-01-30 01:58

Is there a generally accepted way to comment functions in Python? Is the following acceptable?

#########################################################
# Create         


        
10条回答
  •  故里飘歌
    2021-01-30 02:24

    The principles of good commenting are fairly subjective, but here are some guidelines:

    • Function comments should describe the intent of a function, not the implementation
    • Outline any assumptions that your function makes with regards to system state. If it uses any global variables (tsk, tsk), list those.
    • Watch out for excessive ASCII art. Having long strings of hashes may seem to make the comments easier to read, but they can be annoying to deal with when comments change
    • Take advantage of language features that provide 'auto documentation', i.e., docstrings in Python, POD in Perl, and Javadoc in Java

提交回复
热议问题