×

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.

Pesquisar
Categorias
Leia mais
Outro
特殊バーンインボード業界の最新市場動向:売上、価格、販売数量の分析レポート2025
2025年6月5日に、QYResearch株式会社(所在地:東京都中央区)は「特殊バーンインボード―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の最新調査資料を発...
Por Qyresearch Jasmine1 2025-06-05 03:29:00 0
Health
Redefining Tooth Replacement with Advanced Implants
Tooth loss isn’t just about gaps in your smile it affects how you chew, speak, and feel...
Por Emergency Dentist 2025-06-05 09:45:46 0
Outro
Sodium Tripolyphosphate Market In-Depth Analysis: Industry Outlook & Region Forecast by Fact MR
The global sodium tripolyphosphate market is expected to be valued at USD 2.62 billion...
Por Akshay Gorde 2025-05-28 12:39:49 0
Outro
ホモポリマーPVCの世界市場:成長トレンドと主要プレイヤーの競争戦略2025-2031
2025年6月10日に、YH Research株式会社(本社:東京都中央区)は、調査レポート「グローバルホモポリマーPVCのトップ会社の市場シェアおよびランキング...
Por Krystal Lin 2025-06-10 06:33:00 0
Networking
7 Reasons Why Greener Hills Is the Ideal Location for Luxury Homes in Utah
When it comes to finding the perfect location for a luxury home in Utah, Greener Hills stands out...
Por Alan Man 2025-05-22 10:21:52 0