×

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.

Pesquisar
Categorias
Leia Mais
Information Technology
Travel in Style: Group Transportation in East Bay & Sacramento Valley
Whether you're planning a wine tour in Sacramento Valley or a wedding celebration in the East...
Por Quality Travel 2025-06-05 17:43:23 0
Information Technology
種子洗浄機業界分析レポート2025:市場規模、産業調査、最新動向、成長機会
QYResearch株式会社(所在地:東京都中央区)は、最新の調査資料「種子洗浄機―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」を2025年5月12日より発行しま...
Por Qyresearch Jasmine1 2025-05-12 06:03:50 0
Outro
Freight Railcar Repair Market Size, Growth & Research Report (2025-2033) | UnivDatos
According to the UnivDatos, the rising investment in railcar fleet and route expansion, and...
Por Ahasan Ali 2025-05-12 12:40:06 0