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

What is the Python multi-line comment symbol?

青灯夜游
青灯夜游Original
2023-02-02 18:44:4515225browse

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 个单引号分别作为注释的开头和结尾
可以一次性注释多行内容
这里面的内容全部是注释内容
'''

or

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

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:

'''
外层注释
    '''
    内层注释
    '''
'''

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("#是单行注释的开始")

Running result:

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

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!

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