×

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.

Rechercher
Catégories
Lire la suite
Autre
Solar Street Lighting Market - Market Size, Share, and Future Outlook
Solar Street Lighting Market Analysis The solar street lighting market has witnessed substantial...
Par Reshama Patil 2025-06-04 05:40:48 0
Autre
マルチコンパクトヤーン市場の発展動向:シェア、成長率、機会、今後の展望2025-2031
2025年6月5日に、YH Research株式会社(本社:東京都中央区)は、調査レポート「グローバルマルチコンパクトヤーンのトップ会社の市場シェアおよびランキング...
Par Krystal Lin 2025-06-05 06:07:06 0
Health
Anchoring Trust: How the Marine Insurance Market is Evolving
The marine insurance sector plays a critical role in global trade and shipping by protecting...
Par Mayur Gunjal 2025-05-14 06:29:16 0
Shopping
Corteiz Clothing Must-Haves for Women: Trendy Streetwear Styles You’ll See Everywhere in 2025
Corteiz Clothing Must-Haves For Women: The Styles You'll See Everywhere Fashion trends come and...
Par Hoodiesand Tshirt1122 2025-05-31 06:09:14 0