×

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.

Site içinde arama yapın
Kategoriler
Read More
Other
繊維強化ポリマー複合材料業界分析レポート2025-2031:市場規模、産業調査、最新動向、成長機会
2025年6月5日に、QYResearch株式会社(所在地:東京都中央区)は、「繊維強化ポリマー複合材料―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の調査資料を...
By Xu Shuyun 2025-06-05 09:47:35 0
Other
Mpox Treatment Market Size, Share, Trends & Forecast to (2024-2032) | UnivDatos
According to the Univdatos, the rise of prevalence of mpox, increasing mpox vaccination,...
By Tanmay Gupta 2025-06-04 13:02:15 0
Other
Insulating Glass Window Market: Business Outlook and Emerging Growth Factors, Forecast to 2033
Insulating Glass Window Industry Outlook 2025: A report was released freshly that sheds lots of...
By Tejask Kam 2025-05-20 13:06:01 0
Home
The Rise of Smart Homes: How They’re Changing the Market
In recent years, the concept of smart homes has moved from science fiction to a tangible reality...
By Deepika Ahluwalia 2025-05-20 11:27:42 0
Other
Exquisite Custom Soap Boxes That Elevates Your Brand
In today's competitive market, packaging is just as important as the quality of a product and...
By Empress Packaging 2025-05-21 17:10:49 0