×

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.

Căutare
Categorii
Citeste mai mult
Alte
Love Shayari in Hindi for Girlfriend
Romantic Love Shayari in Hindi for Girlfriend – Express Your Heart with Words Looking for...
By Technology Welldone 2025-06-07 08:39:52 0
Alte
Electric Timer Switches Market Boosted by Consumer Energy Awareness
Electric Timer Switches Market is driven by energy-efficient automation demand, smart building...
By Lisa Tate 2025-05-29 12:24:52 0
Information Technology
What is a MEV Bot? A Deep Dive into Maximal Extractable Value
Introduction In the developing realm of decentralised finance (DeFi), an invisible conflict...
By Aana Ethan 2025-05-31 10:15:16 0
Alte
Aerospace Electronics Market Size, Share & Trend Analysis 2025-2034
Global Aerospace Electronics Market: Industry Trends, Share, Size, Growth, Opportunity and...
By Tushar Jane 2025-05-07 05:32:55 0