How to comment python code

Notes

The comment is the explanation and description of the code. The purpose is to make it easy for others to understand. In order to let others know what this code is for at a glance. The correct program notes generally include preface notes and functional notes. The main content of the preamble comment includes the interface of the module, the description of the data and the function of the module. The main content of the functional comment of the module includes the function of the block, the function of the sentence and the state of the data.

Classification of annotations

1. Single line comment

Start with #, and everything on the right side of # is used as an explanation, not the actual program to be executed, and serves as an auxiliary explanation

I am a comment, you can write a functional description here

print("My above line is a comment to me")

2. Multi-line comments

Multi-line comments can be three pairs of double quotation marks or three pairs of single quotation marks. Yes, you have heard it right. There are three pairs. None of them can be less. Also, single quotation marks and double quotation marks can be used, but don’t be foolish. A double quotation mark, three single quotation marks on one side, single quotation marks are single quotation marks, and double quotation marks are double quotation marks.

"""

I am multi-line comment 1

I am multi-line comment 2

I am multi-line comment 3"""
print("My above is a multi-line comment")

Content supplement:

We can output the comment of the function in the following example:

def a():'''This is the docstring'''
 pass
print(a.__doc__)

This is the end of this article on how to annotate python code. For more information about how to annotate python, please search ZaLou.Cn

Recommended Posts

How to comment python code
How to wrap in python code
How to use code running assistant in python
How to set code auto prompt in python
Python how to move the code collectively right
Python code to find bugs(7)
Python code to find bugs(4)
Python code to find bugs (3)
Python code to find bugs(9)
How to write Pythonic code
How to learn python quickly
How to uninstall python plugin
Python code to find bugs(6)
Python code to find bugs (1)
Python code to find bugs(8)
How to understand python objects
Python code to find bugs(5)
How to use python tuples
How to use python thread pool
How to write python configuration file
How to save the python program
How to omit parentheses in Python
How to install Python 3.8 on CentOS 8
How to install Python 3.8 on Ubuntu 18.04
How to write classes in python
How to filter numbers in python
How to read Excel in Python
How to install Python on CentOS 8
How to solve python dict garbled
How to view errors in python
How to write return in python
How to view the python module
How to understand variables in Python
How to clear variables in python
How to understand python object-oriented programming
Python handles operation code to execl
How to use SQLite in Python
How to verify successful installation of python
How to make a globe with Python
How to use and and or in Python
How to delete cache files in python
How to introduce third-party modules in Python
How to represent null values in python
How to save text files in python
How to use PYTHON to crawl news articles
How to write win programs in python
How to run id function in python
How to install third-party modules in Python
How to custom catch errors in python
01. Introduction to Python
200 lines of Python code to achieve snake
How to write try statement in python
How to define private attributes in Python
R&D: How To Install Python 3 on CentOS 7
How to add custom modules in Python
How to process excel table with python
How to understand global variables in Python
How to view installed modules in python
How to install Python2 on Ubuntu20.04 ubuntu/focal64
How to debug python program using repr
How to learn the Python time module