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
Europe Food Flavors Market Demand: Growth, Share, Value, Size, and Insights
"Executive Summary Europe Food Flavors Market :  Data Bridge Market Research...
By Shweta Kadam 2025-06-24 06:23:18 0
Other
Corporate Photography in Dubai
Baby & Corporate Photography in Dubai – UAE Photographer Capturing Precious Moments...
By Business Maker 2025-07-12 17:42:17 0
Other
Why Contractors Rely on Detailed Shop Drawings for Smooth Execution?
In the fast-paced world of construction, precision and clarity are key to avoiding costly delays...
By McLine Studios 2025-05-19 08:59:22 0
Other
Rare But Serious: Forecast of the PML Treatment Market
"Executive Summary Progressive Multifocal Leukoencephalopathy Treatment Market :...
By Dbmrraaj Sinha 2025-06-24 07:17:40 0
Party
8 Tips for Achieving Your Dream Wedding in Manchester
Are you planning to get married in Manchester? Whether you live there or are having a destination...
By Ali Ana 2025-06-29 02:08:44 0
Omaada - A global social and professionals networking platform https://www.omaada.com