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.

Zoeken
Categorieën
Read More
Other
Active Protection System Market Latest Trend, Growth, Size, Application & Forecast By 2031
The comprehensive use of integrated methodologies yields a wonderful Active Protection System...
By Bhavna Kubade 2025-06-26 12:26:48 0
Spellen
Discover Exciting Features in the New Live22 APK Version
The latest update brings faster performance and smoother gameplay. Enjoy enhanced graphics,...
By Live22 Casino 2025-05-20 04:45:53 0
Other
Steam Turbine Service Market Surges Due to Thermal Plant Overhauls
Steam Turbine Service Market is driven by rising power demand, aging assets, and the need for...
By Lisa Tate 2025-05-27 10:34:12 0
Other
Asia-Pacific Temporary Power Market Analysis, Demand Drivers, and Forecast
Asia Pacific Temporary Power Market: The Asia-Pacific Temporary Power Market reflects the...
By Reshama Patil 2025-06-10 06:02:01 0
Omaada - A global social and professionals networking platform https://www.omaada.com