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.

Cerca
Categorie
Leggi tutto
Altre informazioni
Digital Construction: Market Forecast for Management Software in Asia-Pacific
"Executive Summary Asia-Pacific Construction Management Software Market :   The...
By Dbmrraaj Sinha 2025-07-01 05:43:33 0
Altre informazioni
光電式直読式水道メーター調査レポート:市場規模、産業分析、最新動向、予測2025-2031
2025年7月16日に、QYResearch株式会社(所在地:東京都中央区)は、「光電式直読式水道メーター―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の調査資料...
By Liu Yuan 2025-07-16 06:21:52 0
Altre informazioni
Maritime B.SC Nautical Science
PSSR Maritime Training, Maritime Safety Course, & Nautical Science Programs At Eurotech...
By Technology Welldone 2025-07-17 10:22:45 0
Food
Why Buffalo Cow Ghee is the Best Choice for Cooking and Health
In the world of traditional Indian cooking and holistic health, few ingredients hold the same...
By DCc Ghee 2025-05-31 15:11:02 0
Omaada - A global social and professionals networking platform https://www.omaada.com