05 How to write comments in Python?

0
41

Like other programming languages Python also has commenting capability for the purpose of in-code documentation.

Single Line Comment:

Comments start with a #, and Python will render the rest of the line as a comment: 

Example:

#This is a comment.
print("Hello, World!")

Or

print("Hello, World!") #This is a comment

Multy-Line Comment:

In-fact Python does not have any syntax for multi-line comments. To add a multiline comment you could insert a # for each line:

Example:

#This is a comment
#written in
#more than just one line
print("Hello, World!")

Or, you can also use a multiline string for multi-line comment.

Python ignores string literals that are not assigned to a variable, you can add a multiline string (triple quotes) in your code, and place your comment inside it.

Example:

"""
This is a comment
written in
more than just one line
"
""
print("Hello, World!")

As long as the string is not assigned to a variable, Python will read the code, but then ignore it, and you have made a multiline comment.

Suche
Kategorien
Mehr lesen
Andere
Luxury Goods Resale Market: Trends, Size, and Forecast Analysis (2024-2032) | UnivDatos
According to the UnivDatos, the increasing sustainability consciousness among consumers,...
Von Univ Datos 2025-07-02 08:51:11 0
Andere
急速硬化ゼラチンの最新市場動向:業界成長率、競争環境、今後の見通し2025-2031
2025年6月10日に、YH Research株式会社(本社:東京都中央区)は、調査レポート「グローバル急速硬化ゼラチンのトップ会社の市場シェアおよびランキング...
Von Krystal Lin 2025-06-10 06:20:27 0
Andere
Europe Ice Maker Market – Brief on growth, key changes, and market direction.
"Executive Summary Europe Ice Maker Market : CAGR Value The Europe ice maker market...
Von Shim Carter 2025-07-08 06:54:55 0
Andere
密閉型ディスコネクトスイッチの最新調査レポート:市場規模、競合環境、成長要因2025
QYResearch株式会社(所在地:東京都中央区)は、最新の調査資料「密閉型ディスコネクトスイッチ―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」を2025年7月...
Von Liu Yuan 2025-07-04 05:46:11 0
Omaada - A global social and professionals networking platform https://www.omaada.com