×

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.

Zoeken
Categorieën
Read More
Networking
Southeast Asia Battery Energy Storage System Market Projected to Expand Rapidly with Considerable CAGR by 2030
MarkNtel Advisors recently published a detailed industry analysis of the Southeast Asia...
By Jack Daniel 2025-06-10 13:14:52 0
Other
Best Digital Marketing Expert in Kochi
Best Digital Marketing Expert in Kochi – George Chacko | Digital Parrots Kochi Looking for...
By Technology Welldone 2025-06-06 11:37:42 0
Other
ダブルプラットフォームスクリューマシンの世界市場調査レポート:規模、現状、予測2025-2031
QYResearch株式会社(所在地:東京都中央区)は、最新の調査資料「ダブルプラットフォームスクリューマシン―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」を20...
By Xu Shuyun 2025-06-06 08:36:52 0
SEO
広範囲インテリジェント差圧水位計の世界市場レポート:主要企業分析、競争環境、成長戦略2025
2025年6月10日に、QYResearch株式会社(所在地:東京都中央区)は、「広範囲インテリジェント差圧水位計―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の...
By Qyresearch Jasmine1 2025-06-10 06:27:05 0
Other
リン酸エステル系難燃剤業界の商業モデル分析:市場成長の原動力と企業戦略2025
2025年6月6日、YH Research株式会社(本社:東京都中央区)は、調査レポート「グローバルリン酸エステル系難燃剤市場のトップ企業ランキングと市場シェア...
By Krystal Lin 2025-06-06 06:21:23 0