Let’s learn how to add comments in Python code. Code comments are useful to explain the code that allows making the code more readable & easy to understand.
Here is the source code to demonstrate the use of the comments in Python code
#This is a comment that describes the below code that it prints Hello, World! print("Hello, World!")
Below is the output of the above code
Hello, World!
As you can see from the above code & output comments in Python code can be added starting with # and Python will ignore all the comments starting with #
Python comments can also be placed at the end of the line and Python will ignore those as well. The below code shows how to add comments in Python code at the end of the line
print("Hello, World!") #This is a comment that describes the below code that it prints Hello, World!
How to add Multiline Comments in Python Code
Comments in code are useful to explain the code that allows making the code more readable & easy to understand.
The Python code does not really have a syntax for multiline comments. You will have to insert a # at the start of each line for multiline comments
Here is the source code to demonstrate how to add multiline comments in Python code
#This is a comment that #describes the below code #that it prints Hello, World! print("Hello, World!")
Below is the output of the above code
Hello, World!
As you can see from the above code & output multiline comments in Python code can be added by starting each line with #
Summary
You can also check my series on Python for Beginners – Series: Python Tutorial – Learn Python Programming for Beginners
References – Python Documentation
Please provide your suggestions & feedback in the comments section below
Hope you found this article useful. Please support the Author
