深度阅读

How to write Comments in Python3?

作者
作者
2023年08月22日
更新时间
8.75 分钟
阅读时间
0
阅读量

In Python, you can write single-line comments using the hash symbol #. Any code after the # symbol on that line will be ignored by the Python interpreter. For example:

# This is a single-line comment in Python

To write multiline comments in Python, you can use either a multiline string enclosed within triple quotes ''' or """ or use multiple single-line comments. The former is more commonly used for documentation purposes. Here’s an example:

'''
This is a multiline comment in Python
It can span across multiple lines
'''

or

# This is a multiline comment
# in Python using multiple single-line comments
# It can span across multiple lines

It’s important to note that while you can write long multiline comments, PEP 8 (the Python style guide) suggests limiting line length to 72 characters for inline comments and docstrings.

相关标签

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。