Python入门示例系列07 Python注释

 

Python中的注释有单行注释(line comment)多行注释(paragraph comment,block comment)

Python中单行注释以 # (hash, pound) 开头,例如:

# 这是一个单行注释 a comment line
print("Hello!") # 这是一个单行注释 a comment line

示例:

# this is the first comment
spam = 1  # and this is the second comment
          # ... and now a third!
text = "# This is not a comment because it's inside quotes."

 



多行注释三个单引号 ''' 或者三个双引号 """ 将注释括起来,例如:
1、三个单引号(''')

'''
这是多行注释 a paragraph comment
这是多行注释 a paragraph comment
这是多行注释 a paragraph comment
'''
print("Hello!")


2、三个双引号(""")
 

"""
这是多行注释 a paragraph comment
这是多行注释 a paragraph comment
这是多行注释 a paragraph comment
"""
print("Hello!")

 

PyCharm 里面使用注释:

Code 菜单,Comment with Line Comment,快捷键是 CTRL+ /

Code 菜单,comment with block comment (Block comments do not apply to Python scripts!)

 

 

 

 

备注:

# the hash character,pound sign

comment 注释

line comment 行注释

block comment 块注释

 

总目录:https://www.cnblogs.com/emanlee/p/15816554.html

 

 

REF

https://www.runoob.com/python3/python3-basic-syntax.html

https://www.runoob.com/python3/python3-comment.html

 https://www.xdbcb8.com/forum/topic/243

posted @ 2022-01-17 20:41  emanlee  阅读(1361)  评论(0编辑  收藏  举报