×

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.

Site içinde arama yapın
Kategoriler
Read More
Information Technology
Expanding Global Trade: Prism Gold’s Impact on Pakistan’s Exports
In an increasingly interconnected world, global trade plays a pivotal role in the economic growth...
By Josephine Handy 2025-05-23 06:30:22 0
Information Technology
Top 5 Reasons to Choose Ride-Sharing App Development
Are you curious about starting your ride-sharing business? But, stuck in the confusion of...
By Leo Parker 2025-05-19 11:10:31 0
Other
How to Choose the Right Truck Repair Partner for Your Fleet
When your trucks are your business, downtime isn’t just inconvenient, it’s expensive....
By Joseph Brad 2025-06-02 10:42:27 0
Python
Simple Academic Django Projects with Source Code to Learn Django | Python Codeverse
Django is a high-level Python web framework which encourages rapid development and clean,...
By Python Codeverse 2025-06-01 09:26:33 0