×

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.

Pesquisar
Categorias
Leia Mais
Outro
Trusted Man and Van Services in London – House Movers
When you’re planning a move in London, whether it’s a single item or a full...
Por Abu Harera 2025-06-05 12:37:59 0
Outro
Metaverse in Real Estate Market Analysis and Growth Opportunities 2025-2034 Forecast
The worldwide "Metaverse in Real Estate Market" 2025 Research Report presents a professional and...
Por ASHWINI GOURKHEDE 2025-05-23 05:45:37 0
Outro
Top Roofing Service in Southall | Bal Roofing Experts
If you’re looking for a trusted roofing service in Southall, Bal Roofing is your go-to...
Por Abu Harera 2025-06-06 07:05:57 0
Outro
Swim Academy Singapore
Mermaids Swim Academy – Trusted Swimming Academy in Singapore Looking for the perfect place...
Por Technology Welldone 2025-06-07 08:41:21 0