What is the proper way to comment functions in Python?

前端 未结 10 1598
情书的邮戳
情书的邮戳 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:20

    The correct way to do it is to provide a docstring. That way, help(add) will also spit out your comment.

    def add(self):
        """Create a new user.
        Line 2 of comment...
        And so on... 
        """
    

    That's three double quotes to open the comment and another three double quotes to end it. You can also use any valid Python string. It doesn't need to be multiline and double quotes can be replaced by single quotes.

    See: PEP 257

提交回复
热议问题