Comments in Python


How to use comments in python?

When working in any programming language, you include comments in the code to notate your work.
This details what certain parts of the code, and why use this, easily identify other programmer.
In short, It describes what’s going on inside a program so that a person looking at the source code does not have a hard time figuring it out.

Learn about installation of python, click here
Click here, to learn about data types in python.

How many types of comment in python?

Two types of comments,

  • Single line comments
  • Multiline comments

Note : When we run our code that time program automatically ignores our comment.

Let’s describe each of them with example.

=> Single line comments

Python uses the hash symbol (#) to start writing a single line comment.

Syntax :

#{Write your meaning full comment}


#This is a single line comment in python
print("Hello this is single line comment")


Hello this is single line comment

Note: We can see here, our comments not print, because this one automatically ignores.

=> Multi line comments

Multi line comments doing this, is to use triple quotes, like “”” .
These triple quotes are generally used for multi line string comments.

Syntax :

“”” { Write our comment here,
this is multi line comment } “””


""" This is also a Example of Multi line comments in python.
If you are using python on enterprises mode,
it is very high level support fir transaction processing

print("Hello this is Multi line comment example")


Hello this is Multi line comment example

Note: We can see here, our comments not print, because this one automatically ignores.

Now, if you want to check which comment you place inside the code, this one we can easily identify using __doc__

=> Docstring

Docstring is a short form of documentation strings.
Triple quotes are used while writing docstring in python program.

Example :

def msg(name):
	"""This is docstring demo"""
	print("hi, "+name+", Have a nice day!")


Output :
“””This is docstring demo”””
hi, Python, Have a nice day!

Leave a Comment

Your email address will not be published.

Latest Blog