- Python基礎(chǔ)教程
- 在SublimeEditor中配置Python環(huán)境
- Python代碼中添加注釋
- Python中的變量的使用
- Python中的數(shù)據(jù)類型
- Python中的關(guān)鍵字
- Python字符串操作
- Python中的list操作
- Python中的Tuple操作
- Pythonmax()和min()–在列表或數(shù)組中查找最大值和最小值
- Python找到最大的N個(前N個)或最小的N個項目
- Python讀寫CSV文件
- Python中使用httplib2–HTTPGET和POST示例
- Python將tuple開箱為變量或參數(shù)
- Python開箱Tuple–太多值無法解壓
- Pythonmultidict示例–將單個鍵映射到字典中的多個值
- PythonOrderedDict–有序字典
- Python字典交集–比較兩個字典
- Python優(yōu)先級隊列示例
在Python(或任何其他編程語言)中,注釋用于解釋源代碼。注釋描述了代碼,這有助于將來維護應(yīng)用程序。
python中的注釋
# prints 4
print(2 + 2)
print(2 + 3) # prints 5
"""
prints the sum of
two numbers which are 2 and 2
"""
print(2 + 2)
Python中的注釋類型
Python支持編寫簡單的單行注釋以及多行注釋。
單行注釋
一個簡單的單行注釋將以井號(#)字符開頭。Python運行時會忽略#字符后寫的任何文本,并將其視為注釋。
單行注釋
# This is a simple comment
print(2 + 2)
print(2 + 3) # prints 5
多行注釋
Python沒有什么特別的東西可以寫多行注釋。要編寫它,我們可以編寫多個單行注釋。
我推薦這種形式的評論。
多行注釋
# This statement
# prints the sum of
# two numbers which are 2 and 2
print(2 + 2)
我們可以利用未分配給變量的多行字符串文字(使用三引號)。Python會忽略未分配給任何變量的字符串文字,因此它不會影響程序執(zhí)行。
Un-assigned string literal
"""
This statement
prints the sum of
two numbers which are 2 and 2
"""
print(2 + 2)
將有關(guān)在python中編寫注釋的問題交給我。
學(xué)習愉快!
作者:分布式編程
出處:https://zthinker.com/
如果你喜歡本文,請長按二維碼,關(guān)注 分布式編程

分布式編程小程序.jpg