Home  >  Article  >  Backend Development  >  What does a single line comment in python start with?

What does a single line comment in python start with?

(*-*)浩
(*-*)浩Original
2019-07-03 15:14:5330316browse

It is also important to learn to add necessary comments to the program. Comments can not only be used to explain the role and function of certain parts of the program (describing the function of the code in natural language), but can also temporarily remove the code when necessary, which is a good helper for debugging the program.
What does a single line comment in python start with?
Of course, the biggest effect of adding comments is to improve the readability of the program! Many times, I would rather write an application myself than improve other people's code. The lack of reasonable comments is an important reason. (Recommended learning: Python video tutorial)

Although good code can stand on its own, we never know who will read this code in the future and whether he is related to you. Same idea. Or after a period of time, you may not know the purpose of writing this code at that time.

In general, once a certain part of the program is commented out, it will be ignored by the Python interpreter. In other words, this part of the program will not be executed.

Generally speaking, reasonable code comments should account for about 1/3 of the source code. The Python language allows null characters or comments to be inserted anywhere except between identifiers and strings.

Comments in Python include single-line comments and multi-line comments.

Introducing single-line comments here:

Single-line comments in Python begin with #, that is, starting from the symbol '#' and ending at the newline. Part of the content is used as comment content. When the program is executed, this part of the content will be ignored.

For example:

# 这是一个注释print
("Hello, World!")

can also be the right side of the comment code, for example:

print ("Hello World!") #这是一行简单的注释

Based on the role of comments in the program, Although the placement locations of the above two methods are different, the execution result of the program is the same, both output "Hello World!".

For more Python related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of What does a single line comment in python start with?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn