Home > Backend Development > Python Tutorial > What is the Python multi-line comment symbol?

What is the Python multi-line comment symbol?

青灯夜游
Release: 2023-02-02 18:44:45
Original
15320 people have browsed it

Python multi-line comment symbol is three consecutive single quotes "'''" or three consecutive double quotes """"", which is used to comment on multiple lines of content in the program at once (including one line ), syntax "'''Comment content'''" or """"Comment content"""". Multi-line comments are usually used to add copyright or functional description information to Python files, modules, classes or functions, etc., and are not supported Nesting.

What is the Python multi-line comment symbol?

The operating environment of this tutorial: windows7 system, python3 version, DELL G3 computer

Comments are used to prompt the user Or explain the role and function of some code, it can appear anywhere in the code. The Python interpreter will ignore the comment when executing the code and do not do any processing, as if it does not exist.

In During the process of debugging a program, comments can also be used to temporarily remove useless code.

The biggest role of comments is to improve the readability of the program. A program without comments is simply a bible that makes people vomit blood. !

Python multi-line comments

Multi-line comments refer to the contents of multiple lines (including one line) in a one-time comment program.

Python uses three consecutive single quotes ''' or three consecutive double quotes """ to comment multi-line content. The specific format is as follows:

'''
使用 3 个单引号分别作为注释的开头和结尾
可以一次性注释多行内容
这里面的内容全部是注释内容
'''
Copy after login

or

"""
使用 3 个双引号分别作为注释的开头和结尾
可以一次性注释多行内容
这里面的内容全部是注释内容
"""
Copy after login

Multi-line comments are usually used to add copyright or functional description information to Python files, modules, classes or functions.

Notes

1) Python multi-line comments do not support nesting, so the following writing is wrong:

'''
外层注释
    '''
    内层注释
    '''
'''
Copy after login

2) Regardless of Whether multi-line comments or single-line comments, when comment characters appear as part of the string, they can no longer be regarded as comment marks, but should be regarded as part of the normal code, for example:

print('''Hello,World!''')
print("""http://c.biancheng.net/cplus/""")
print("#是单行注释的开始")
Copy after login

Running result:

Hello,World!
http://c.biancheng.net/cplus/
#是单行注释的开始
Copy after login

For the first two lines of code, Python does not treat the three quotation marks here as multi-line comments, but treats them as the start and end marks of the string.

For the third line of code, Python does not treat the pound sign as a single-line comment, but treats it as part of the string.

【Related recommendations: Python3 video tutorial

The above is the detailed content of What is the Python multi-line comment symbol?. 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