×

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.

Zoeken
Categorieën
Read More
Other
Pultruded Spar Cap Market Accelerates with Wind Energy Expansion and Composite Material Advancements
The Pultruded Spar Cap Market is witnessing significant growth, driven by the...
By Ananya Birla 2025-05-28 13:23:31 0
Other
Meghalaya: The Land of Clouds
Meghalaya, meaning “Abode of Clouds”, is one of India’s most mesmerizing...
By Travenjo Tour 2025-05-26 11:06:00 0
Information Technology
Impacts of Promoting Green Building Materials on Asphalt Mixing Plants
The promotion of green building materials is reshaping the construction industry, and asphalt...
By Macroad AsphaltPlant 2025-05-22 01:10:20 0
Other
Germany Synchronous Condenser Market: Enhancing Grid Reliability in Energy Transition
Germany Synchronous Condenser Market The Germany synchronous condenser market has been...
By Reshama Patil 2025-06-06 06:31:22 0
Information Technology
The Automobile Half Bridge Drivers Market
IntroductionThe Automobile Half Bridge Drivers Market is experiencing significant...
By HARSH Verma 2025-06-08 17:58:41 0