×

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.

Rechercher
Catégories
Lire la suite
Autre
Metal Chelates Market Research, Review, Applications and Forecast to 2025
Global Metal Chelates Market: Industry Trends, Share, Size, Growth, Opportunity and Forecast...
Par Tushar Jane 2025-05-07 05:33:06 0
Autre
Wearable Patient Sensor Market Growth and Forecast Analysis 2034
The most recent report published by Vantage Market Research indicates that the "Wearable Patient...
Par ASHWINI GOURKHEDE 2025-05-29 06:26:31 0
Autre
Advanced Air Mobility Market Trends, Opportunities, Current Analysis and Forecast (2024-2032) I UnivDatos
Introduction: According to the Universal Data Solutions analysis, growing demand for urban...
Par Ankit Rath 2025-06-05 06:58:17 0
Health
한국 신경계 기기 시장 규모, 성장, 동향 및 기회 2025-2033
한국 신경계 기기 시장 개요 시장 통계 기준 연도:2024 역사적 연도:2019-2024 예측 연도:2025-2033 2024년 시장 규모: 2억 4천만 달러 2033년 시장...
Par Harutoleo Leo 2025-06-04 07:05:31 0