×

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.

Поиск
Категории
Больше
SEO
Fashion World Taken Over by Adwysd joggers Streetwear
Streetwear has always been a canvas for self-expression, and lately, one brand is making waves in...
От Vertabraec Vertabraec 2025-05-26 21:03:06 0
Другое
Asia-Pacific Rooftop Solar EPC Market Advances with Smart Tech Usage
Asia-Pacific Rooftop Solar EPC Market is rising due to&nb...
От Lisa Tate 2025-05-20 12:09:08 0
Другое
Assisted Reproductive Technology Market Analysis by Size, Growth, & Research Report (2025–2033) | UnivDatos
According to the UnivDatos, rising infertility rates, delayed marriages, and growing...
От Ahasan Ali 2025-05-21 08:41:28 0
Другое
Energy Management Systems Market Analysis and Growth Opportunities 2025-2034 Forecast
The most recent report published by Vantage Market Research indicates that the "Energy Management...
От ASHWINI GOURKHEDE 2025-05-21 06:07:38 0