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.

Pesquisar
Categorias
Leia Mais
Shopping
Tom Brady has more playoff wins than every other QB in the 2020 postseason combined
For the first time in 10 years, the will be opening the postseason in the wild-card round, and...
Por Bria Wilderman 2025-07-21 10:15:00 0
Outro
Telepresence Robot Market Insights: Growth, Share, Value, Size, and Analysis
"Executive Summary Telepresence Robot Market : CAGR Value The Global Telepresence Robot...
Por Shweta Kadam 2025-07-18 16:57:51 0
SEO
クラウンエーテル市場競争分析:主要企業、ランキング、投資動向2025
2025年6月30日に、QYResearch株式会社(所在地:東京都中央区)は「クラウンエーテル―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の最新調査資料を発行...
Por Qyresearch Jasmine1 2025-06-30 07:19:35 0
Drinks
Fresh Meat Packaging Market Industry Statistics: Growth, Share, Value, Insights, and Trends
"Executive Summary Fresh Meat Packaging Market : Data Bridge Market Research analyses...
Por Mike Warn 2025-06-20 08:13:39 0
Outro
Nasal Polyposis Drugs Market Insights: Growth, Share, Value, Size, and Analysis
"Executive Summary Nasal Polyposis Drugs Market :   Data Bridge Market...
Por Shweta Kadam 2025-07-04 05:46:11 0
Omaada - A global social and professionals networking platform https://www.omaada.com