微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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 commnet 块注释

 

 

系列目录

Python入门示例系列01 为什么学Python

Python入门示例系列02 Python 语言的特点

Python入门示例系列03 安装Python开发工具

Python入门示例系列04 使用 IDLE Shell

Python入门示例系列05 使用PyCharm

Python入门示例系列06 使用PyCharm单步调试

Python入门示例系列07 Python注释

Python入门示例系列08 基础语法

Python入门示例系列09 Python算术运算

Python入门示例系列10 字符串(初级)

Python入门示例系列11 数据类型

Python入门示例系列12 数据类型转换

 

 

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐