×

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
Car Tinting Gold Coast
Premium Car Tinting Gold Coast – Enhance Your Drive with Ultra Shade Tint Looking for...
By Technology Welldone 2025-06-06 10:59:51 0
Other
Beyond Public Transport: Why Renting a Bus in Mumbai Is Worth Considering
Mumbai's chaotic transport network somehow manages to keep the city moving. Yet certain...
By Shane Debois 2025-06-03 06:11:58 0
Other
リン酸エステル系難燃剤業界の商業モデル分析:市場成長の原動力と企業戦略2025
2025年6月6日、YH Research株式会社(本社:東京都中央区)は、調査レポート「グローバルリン酸エステル系難燃剤市場のトップ企業ランキングと市場シェア...
By Krystal Lin 2025-06-06 06:21:23 0
Other
高耐熱ポリオレフィンバックシート市場競争分析:主要企業、ランキング、投資動向2025
2025年6月6日に、QYResearch株式会社(所在地:東京都中央区)は、「高耐熱ポリオレフィンバックシート―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の調...
By Qyresearch Jasmine1 2025-06-06 06:05:53 0
Games
YYGaming娛樂首選平台,開啟你的極速遊戲世界!
在這個數位娛樂迅速發展的時代,線上遊戲平台不斷推陳出新,但真正能結合娛樂性、公平性與高品質服務的品牌卻不多,而【YYGaming】正是當中最受玩家信賴與喜愛的一個。作為香港領先的綜合娛樂平台,Y...
By Imran Ali 2025-05-28 07:25:24 0