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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM