×

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.

Cerca
Categorie
Leggi tutto
Altre informazioni
Electronic Filtration Market: Safeguarding Electronics from Contaminants and Interference
As the electronics industry grows, ensuring the quality and reliability of components is becoming...
By Myra Miller 2025-06-17 06:00:02 0
Altre informazioni
Surgical Simulators – Enhancing Skills, Improving Outcomes
In the healthcare industry, surgical simulators are increasingly being recognized as an essential...
By Ananya Birla 2025-06-23 06:21:31 0
Altre informazioni
Germany Energy Storage Market – Competitive Insights and Market Forecast
Germany Energy Storage Market Overview: Germany stands at the forefront of global energy...
By Reshama Patil 2025-06-04 05:55:17 0
Altre informazioni
Barrier Coated Flexible Paper Packaging Market: Trends, Opportunities and Forecast to 2034
The global barrier coated flexible paper packaging market has gained significant attention over...
By Harshal Juvale 2025-06-20 06:12:41 0
Altre informazioni
Things to Consider Before You Buy a Television
Buying a new television can be an exciting but overwhelming experience, especially with the wide...
By Nancy Ahuja 2025-05-23 05:20:48 0