×

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.

Поиск
Категории
Больше
Другое
Solving Your Pipeline Problems with Artificial Intelligence
AI to the Rescue: How Smart Technology Is Solving B2B Pipeline Problems for Good In today's...
От Robert Haas 2025-05-14 13:19:52 0
Другое
Cheap Coach Hire Birmingham – Thandi Coaches
If you’re searching for cheap coach hire in Birmingham, look no further...
От Abu Harera 2025-06-05 11:15:31 0
Другое
High Speed Engine Market Research, Review, Applications and Forecast to 2025
The most recent report published by Vantage Market Research indicates that the "High Speed Engine...
От ASHWINI GOURKHEDE 2025-05-08 05:00:35 0
Другое
5 Days India Golden Triangle Tour – A Journey Through Culture and Heritage
The 5 Days India Golden Triangle Tour is an unforgettable experience for travelers who want to...
От Fair Deal 2025-06-04 17:50:29 0