Python实现多行注释的另类方法

WBOY
Release: 2016-06-06 11:31:51
Original
1116 people have browsed it

Python程序的注释感觉很不合群,对于习惯了使用/**/多行注释的人来说,到Python中只能使用#号进行单行注释很痛苦。

代码如下:


# 这里是单行注释
# a = 50
# b = 10
# c = 10


其实我们可以通过多行文本定义的格式实现多行注释:

代码如下:


"""
    # 这里是多行注释
    a = 50
    b = 10
    c = 10
"""


这个方法感觉还不错,跟/**/多行注释用起来没啥区别,这在调试代码的时候很管用,可以直接使用多行文本定义符号注释掉部分代码。也许Python的多行文本定义功能本来也可以充当注释用的,只不过手册上没有明确写是用于多行注释的而已。
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!