Home > Article > Backend Development > Parsing Python code comment specification code
##1. Introduction to code comments
Relevant learning recommendations:
2. Code comment classification
3. Basics of python code comments
name = 'xiaohong' # Single line comment # Single line commentUse three single quotes or three double quotes in Python to indicate multi-line comments. Used when there are too many comments to write, as in the following example:name = 'xiaohong'
'''This is a multi-line comment using three single quotes
"""
'''
This is a multi-line comment using three double quotes
"""
4. Introduction and use of DocStrings
def add(num1,num2): """ 完成传入的两个数之和 :param num1: 加数1 :param num2: 加数2 :return: 和 """ return num1 + num2 print( add.__doc__ )Remarks: DocStrings Document string usage convention: Its first line briefly describes the function function, the second line is blank, and the third line is a specific description of the function.
5. Common writing styles of DocStrings
""" This is a reST style. :param param1: this is a first param :param param2: this is a second param :returns: this is a description of what is returned :raises keyError: raises an exception """5.2 Google style
""" This is a groups style docs. Parameters: param1 - this is the first param param2 - this is a second param Returns: This is a description of what is returned Raises: KeyError - raises an exception """5.3 Numpydoc (Numpy style)
""" My numpydoc description of a kind of very exhautive numpydoc format docstring. Parameters ---------- first : array_like the 1st param name `first` second : the 2nd param third : {'value', 'other'}, optional the 3rd param, by default 'value' Returns ------- string a value in a string Raises ------ KeyError when a key error OtherError when an other error """
6. Some annotation experience
Related learning Recommended:
The above is the detailed content of Parsing Python code comment specification code. For more information, please follow other related articles on the PHP Chinese website!