加入收藏 | 设为首页 | 会员中心 | 我要投稿 汽车网 (https://www.0577qiche.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

Python入门示例系列07 Python注释

发布时间:2023-04-08 14:00:49 所属栏目:教程 来源:
导读:Python中的注释有单行注释(line comment)和多行注释(paragraph comment,block comment):

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

# 这是一个单行注释 a comment line
print("Hello!") # 这是
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、三个双引号(""")

PyCharm 里面使用注释:

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

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

 

(编辑:汽车网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章