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.

Pesquisar
Categorias
Leia mais
Outro
RFIDエレベータコントローラの世界市場調査レポート:規模、現状、予測2025-2031
QYResearch株式会社(所在地:東京都中央区)は、最新の調査資料「RFIDエレベータコントローラ―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」を2025年7...
Por Liu Yuan 2025-07-08 09:45:21 0
Health
Adderall: Unlocking Your Full Potential
The ADHD prescription drug Adderall pills improves cognitive function, focus, and concentration....
Por Hennry Lauren 2025-05-06 11:02:22 0
Health
Human Papillomavirus Vaccine Market Leading Players and Growth Forecast To 2031
The global Human Papillomavirus (HPV) Vaccine Market, valued at US$ 4.0 billion in 2022, is...
Por Jack Wiliam 2025-07-21 13:56:57 0
Outro
Commercial Security Systems Market Forecast: AI Integration, Surveillance Trends & Global Growth
Executive Summary Commercial Security Systems Market : Data Bridge Market Research...
Por Ksh Dbmr 2025-06-26 07:55:09 0
Outro
Emergency Blocked Drains: What to Do First
A blocked drain has a knack for happening when you least expect it. You might be getting dinner...
Por Aspen Pluma 2025-07-15 00:57:56 0
Omaada - A global social and professionals networking platform https://www.omaada.com