×

To install this app on your iPhone, tap Share 🔗 then Add to Home Screen.

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.

Cerca
Categorie
Leggi tutto
Altre informazioni
等方性PETフィルム市場調査レポート:主要企業、競合分析、成長動向2025-2031
QYResearch株式会社(所在地:東京都中央区)は、最新の調査資料「等方性PETフィルム―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」を2025年5月30日よ...
By Moni Ka 2025-05-30 09:44:30 0
Information Technology
電動ローラートランスファー業界レポート:市場動向、機会分析、将来予測2025-2031
2025年5月22日に、QYResearch株式会社(所在地:東京都中央区)は「電動ローラートランスファー―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の最新調査...
By Qyresearch Jasmine1 2025-05-22 06:58:49 0
Information Technology
USB PD受電コントローラー市場競争分析:主要企業、ランキング、投資動向2025
QYResearch株式会社(所在地:東京都中央区)は、最新の調査資料「USB...
By Qyresearch Jasmine1 2025-05-15 06:37:28 0
Altre informazioni
Load Bank Market To Thrive With North American Industrial Growth
Load Bank Market to be led by North America, driven by tech advances and industrial growth from...
By Lisa Tate 2025-06-03 09:08:47 0