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
SEO
ジアミノマレオニトリル(DAMN)の世界市場展望:規模、成長ドライバー、将来予測2025-2031
2025年6月30日に、QYResearch株式会社(所在地:東京都中央区)は「ジアミノマレオニトリル(DAMN)―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の...
By Qyresearch Jasmine1 2025-06-30 07:18:51 0
Other
Digitization vs Digitalization
Digitization vs Digitalization – What’s the Difference? In today’s tech-driven...
By Technology Welldone 2025-06-22 08:02:30 0
Information Technology
Top HR Management Software: Revolutionizing Workforce Administration in the Digital Age
Human Resource (HR) departments have traditionally handled a variety of responsibilities ranging...
By Superworks Technology 2025-06-12 08:15:28 0
Other
Medical Imaging Software Market Trends: Growth, Share, Value, Size, and Analysis
"Executive Summary Medical Imaging Software Market : CAGR Value Data Bridge Market...
By Shweta Kadam 2025-07-07 06:27:56 0
Omaada - A global social and professionals networking platform https://www.omaada.com