×

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
Film
Projection Mapping vs. Traditional Displays: Which One Wins in 2025?
In the ever-evolving world of visual storytelling, 2025 marks a significant year for display...
By Mila Scarle 2025-06-05 08:57:28 0
Alte
Automotive Smart Display Market Unveiling Driving Factors, Strategies, and Forecasted Trends by Fact MR
The global automotive smart display market is expected to reach USD 18.2 billion by...
By Akshay Gorde 2025-06-05 14:17:04 0
Alte
Clear Aligners Market Analysis and Growth Opportunities 2025-2034 Forecast
The worldwide "Clear Aligners Market" 2025 Research Report presents a professional and complete...
By ASHWINI GOURKHEDE 2025-06-10 06:16:16 0
Food
Global Drinks Market Growth, Demand & Forecast Overview to 2030
Global Drinks Market Research Report – 2025 Outlook, Trends, Share, Size & Forecast...
By Akio Komatsu 2025-06-05 10:31:25 0
Alte
Lead Acid Battery Market: Automotive Sector Influence and Market Analysis
Lead Acid Battery Market Demand The demand for lead acid batteries has been consistently robust,...
By Reshama Patil 2025-06-05 07:55:56 0