The beginning of learning any programming language is to learn how to write its comments, which help us understand the purpose of the code.

What is a comment?

The essence of computer programming is to convey information, and good code can not only convey the programmer’s instructions to the computer, but also convey the programmer’s intentions to others who read the code.

Comments exist precisely to help people understand the intent of the code, and they have no effect on the behavior of the program.

Two kinds of comments for Python

Single-line comments

In Python, single-line comments with # are ignored until the end of the line and will not be executed by the Python interpreter.

Multiline comment

Multi-line comments in Python use a pair of triple quotation marks ”’ ”’/””” “”” (in English). Everything between the triple quotation marks is ignored and will not be executed by the Python interpreter.

How to use comments well?

One of the hallmarks of a good developer is his comments: comments where they should be, not comments where they are not needed, and even well-written self-describing functions are themselves comments.

Good comments allow us to maintain our code better and, after a while, return more efficiently to code efficient development.

Comment these:

  • Overall architecture, high-level perspective.
  • Function usage.
  • Important solutions, especially if they are not obvious.

Avoid comments:

  • Describe “how the code works” and “what the code does”.
  • Avoid unnecessary comments when the code is simple enough or self-descriptive enough to not need them.

At the end of the article

These are the basics of computing. If you think my writing is good, please give me a thumbs up. Please scan the qr code below to follow my wechat official account for more Python knowledge

More wonderful python tutorial B stand, please focus on me: www.bilibili.com/video/BV1K8…