×

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.

Buscar
Categorías
Read More
Other
静音電動ガーデンシュレッダー市場調査2025-2031:シェア、産業分析、最新動向、成長機会
2025年6月4日に、QYResearch株式会社(所在地:東京都中央区)は「静音電動ガーデンシュレッダー―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の最新調査...
By Qyresearch Jasmine1 2025-06-04 07:11:44 0
Other
Crafting a Teaching Resume That Speaks Your Subject’s Language
I'll never forget the first time I applied for a middle school science teaching job with a...
By Famida Vp 2025-05-26 13:20:28 0
Other
Leading Property Developers in Dubai Reshaping Urban Living
The UAE has long established itself as a global real estate hub, attracting investors,...
By Mr Umii 2025-05-28 07:28:57 0
SEO
タブレットスケールの世界調査レポート:2031年には170百万米ドルに達する見込み
2025年6月11日に、QYResearch株式会社は「タブレットスケール―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の調査レポートを発表しました。本報告書は、...
By Qyresearch Jasmine1 2025-06-11 03:24:59 0