In this tutorial, we will learn about Comments in Python and we will also cover different examples related to Python Comments. And, we will cover these topics.
- Python Comments
- Multiline Python Comment
- Docstrings Python Comment
- Python indentation
Python Comments
In python or in any other code we generally use the comments to make proper understanding for a code. In the professional world or programmers, every programmer uses the comments in code which will help to prepare them to modify the code if it is required in the future we can use that and make sure to get the proper understanding of the code.
We can see in another programming language such as c or C++ they use the comment statement like // is used for the single-line comment and to comment multiples lines we use /*…. */ in python we use the # to comment on a line and it is used at the beginning of the code.
Example:
# This is the print statement
print("Welcome To PythonTpoint")
Output:
In this code, we use the print statement and with help of #, we add a comment inside this code.
Multiline Python Comment
In Multiline Python Comment we have to use the # at the beginning of the line that will help to make a multiline code here we can understand this with the following example:
# First line of the comment
# Second line of the comment
# Third line of the comment
Code Example:
# Variable p holds value 5
# Variable y holds value 10
# Variable t holds sum of p and y
# Print the result
p = 8
y = 23
t = p+y
print("The sum is:", t)
Output:
In the above code we can see with the help of comments we can understand what is happening in the code as it is very easy to understand and readable for a viewer about this code. We also use the (“””) to add multiline comments. The triple quotes are also used to make a string format.
Docstrings Python Comment
In Docstrings Python Comment it is mostly used in the module, function, class, or method. It is known as Document String Python Comment we can consider the following example:
Example:
def introduce():
"""
This function prints Hi PythonTpoint
"""
print("Hi PythonTpoint")
introduce()
Python indentation
In Python Indentation it is used to define the block of the code. As in other programming languages like java, c, c++ they use the curly braces {} and in python, indentation is used whitespaces are used as an indentation in python.
When we apply indentation we generally keep in mind that we need to use the four white spaces as indentation. It depends upon the user but it must be consistent throughout that block.
Example Code:
py = int(input("Enter the number:"))
if(py%2 == 0):
print("Even Number")
else:
print("Odd Number")
print("Tata Bye Bye !!")
Output:
So, in this tutorial, we discussed Python Comments and we have also covered different examples related to its implementation. Here is the list of examples that we have covered.
- Python Comments
- Multiline Python Comment
- Docstrings Python Comment
- Python indentation
Do Follow:
I have recently started a site, the information you offer on this site has helped me greatly. Thank you for all of your time & work. “The achievements of an organization are the results of the combined effort of each individual.” by Vince Lombardi.
I visit daily some web pages and information sites to read
posts, except this website provides quality based articles.!
Hello! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to get my site to rank for some targeted keywords but I’m not seeing
very good results. If you know of any please share. Appreciate it!
I saw similar blog here: Eco blankets
By no means depart your pet alone in the car.
sugar defender official website Finding Sugar Defender has actually been a game-changer for me, as I have actually always been vigilant
about managing my blood glucose levels. I currently feel empowered and positive in my capability to preserve healthy
degrees, and my newest medical examination have reflected this development.
Having a credible supplement to enhance my a significant
resource of convenience, and I’m truly appreciative for the significant distinction Sugar Protector
has made in my general wellness.