×

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
Other
Household Insecticides Market Rises On Demand For Safer Living Spaces
Household Insecticides Market growth from 2026–2030 will ...
By Lisa Tate 2025-05-19 11:54:09 0
Information Technology
粒状定量包装はかりの世界市場展望:規模、成長ドライバー、将来予測2025-2031
2025年5月8日に、QYResearch株式会社(所在地:東京都中央区)は「粒状定量包装はかり―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の最新調査資料を発行...
By Qyresearch Jasmine1 2025-05-08 05:44:22 0
Other
Mobile Artificial Intelligence Market Growth and Forecast Analysis 2034
The worldwide "Mobile Artificial Intelligence Market" 2025 Research Report presents a...
By ASHWINI GOURKHEDE 2025-05-27 05:30:16 0
Other
Intermodal Chassis Market Analysis by Size, Share, Growth, Trends and Forecast (2024–2032) | UnivDatos
The intermodal chassis market plays a crucial role in the global logistics and transportation...
By Ahasan Ali 2025-06-04 12:51:37 0
Information Technology
グローバルパルス光ファイバーレーザー溶接機市場の産業全体規模とシェア分析2025-2031
2025年5月22日に、QYResearch株式会社(所在地:東京都中央区)は「パルス光ファイバーレーザー溶接機―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の最...
By Qyresearch Jasmine1 2025-05-22 06:59:40 0