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.

Căutare
Categorii
Citeste mai mult
Alte
フラックス洗浄機日本市場分析レポート:市場規模、成長率、主要企業の動向2025-2031
2025年7月18日に、QYResearch株式会社(所在地:東京都中央区)は、「フラックス洗浄機―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の調査資料を発行し...
By Liu Yuan 2025-07-18 01:18:25 0
Art
Asia-Pacific Dish Antennas Market Expands with Increased Satellite Communication and DTH Services
"Executive Summary Asia-Pacific Dish Antennas Market : The Asia-Pacific Dish Antennas...
By Komal Galande 2025-07-04 05:22:29 0
Alte
Gluconates Market Graph: Growth, Share, Value, Insights, and Trends
"Executive Summary Gluconates Market :  Data Bridge Market Research analyses that...
By Shweta Kadam 2025-07-18 04:02:33 0
Alte
Booster Seats Market Companies: Growth, Share, Value, Analysis, and Trends
"Executive Summary Booster Seats Market :  Data Bridge Market Research analyses...
By Shweta Kadam 2025-07-04 06:24:48 0
Information Technology
PSA Market Growth Underscores Need for Consistency in Manufacturing
The global Particle Size Analyzer Market was valued at USD 332.8 Mn in 2021 and is projected to...
By Amit Mohite 2025-06-27 16:28:20 0
Omaada - A global social and professionals networking platform https://www.omaada.com