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 塊注釋
系列目錄
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