×

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.

Search
Categories
Read More
Other
The Ultimate Guide to Buying a Laser Cleaning Machine for Sale
In recent years, laser cleaning technology has revolutionized the way industries handle surface...
By John Kaur 2025-05-23 07:10:07 0
Other
Breaking Down the US$ 2.16 Billion Automotive Engine Oil Pan Market
The global automotive engine oil pan market experienced significant growth from 2018 to 2023,...
By Myra Miller 2025-05-26 12:43:43 0
Other
Thorium Market Analysis by Size, Share, Growth, Trends and Forecast (2024–2032) | UnivDatos
According to the Univdatos Market Insights, rising demand for clean and efficient nuclear energy,...
By Ahasan Ali 2025-05-05 13:51:38 0
Health
How Cenforce Can Improve Your Sex Life and Confidence?
Erectile dysfunction (ED) affects millions of men globally and can lead to not just physical but...
By Grace Walker 2025-05-21 04:36:43 0