What are the comments in python?

coldplay.xixi
Release: 2023-01-03 09:27:55
Original
42893 people have browsed it

Python comments are: 1. Use [#] to indicate a single line comment. A single line comment can be placed as a separate line above the commented line of code; 2. Use three single quotes or three double quotes in Python Quotation marks indicate multi-line comments.

What are the comments in python?

The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer.

Python’s comments are:

1. Single-line comments (line comments)

# is used in Python to represent single-line comments. . Single-line comments can be placed as a separate line above the line of code being commented, or after a statement or expression.

# 这是单行注释
Copy after login
  • When a single-line comment is placed as a separate line above the commented line of code, in order to ensure the readability of the code, it is recommended to add a space after # and then add the comment content .

  • When a single-line comment is placed after a statement or expression, in order to ensure the readability of the code, it is recommended that there be at least two lines between the comment and the statement (or the comment and the expression). spaces.

2. Multi-line comments (block comments)

When there is too much comment content and one line cannot be displayed, you can use multi-line comments. Note. In Python, three single quotes or three double quotes are used to represent multi-line comments.

'''
这是使用三个单引号的多行注释
'''
"""
这是使用三个双引号的多行注释
"""
Copy after login

3. Note that

  • The more comments, the better. For code that is self-explanatory, there is no need to add comments.

  • For complex operations, corresponding comments should be written before starting the operation.

  • For code that is not self-explanatory, comments should be added after the code.

  • Never describe code. Generally, people who read code know the syntax of Python, but they just don’t know what the code is doing.

Related free learning recommendations: python video tutorial

The above is the detailed content of What are the comments in python?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!