×

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
Impact of Remote Work on the Ergonomic Chair Market Growth
The ergonomic chair market has evolved into a crucial segment within the global office furniture...
By Mayur Gunjal 2025-06-06 05:08:37 0
Networking
Aroma Chemicals Market Outlook 2024-2034: Natural Ingredients and Innovation Fuel Expansion
By 2021, the Aroma Chemicals Market was valued at US$ 5.11 billion. It is projected to increase...
By Bablya Bhau 2025-06-09 13:01:18 0
Altre informazioni
Navigating UK Indefinite Leave to Remain with Immigration Solicitors4me, Your Expert Immigration Lawyer in UK
Achieving Indefinite Leave to Remain (ILR) in the United Kingdom is a pivotal milestone...
By Immigration Solicitors 2025-05-23 19:36:01 0
Altre informazioni
North America Toilet Paper: Retail vs Wholesale Market
The toilet paper market in North America has witnessed significant transformation over the past...
By Mayur Gunjal 2025-06-02 08:43:43 0
Altre informazioni
Best Hindi Love Shayari in English
Best Hindi Love Shayari in English – Heartfelt Romantic Shayari by RoopVibes Explore the...
By Technology Welldone 2025-06-06 11:47:06 0