×

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.

Search
Categories
Read More
Information Technology
高圧モーターソフトスターター業界分析レポート2025:市場規模、産業調査、最新動向、成長機会
2025年5月27日に、QYResearch株式会社(所在地:東京都中央区)は「高圧モーターソフトスターター―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の最新調...
By Qyresearch Jasmine1 2025-05-27 08:46:35 0
Networking
Why SAP is important ?
SAP (Systems, Applications, and Products in Data Processing) is significant because it offers...
By Shobha Katkar 2025-05-22 11:48:52 0
Other
Care Management Solutions Market Booming in Size in 2025
The most recent report published by Vantage Market Research indicates that the "Care Management...
By Tushar Jane 2025-05-27 05:13:49 0
Music
Why Every Beginner Should Start with an Acoustic Guitar
Learning to play the guitar is a thrilling and rewarding experience. Whether you're inspired by...
By Online Services 2025-05-16 11:17:55 0