Comments in Python programming language

Comments in Python programming language

Comments are used to explain programming code in any language for the same purpose comments are also used in the python programming language. It can also be used to hide the code as well.

Comments are the most helpful part for programmers to understand the purpose of any program. It enables us to understand the way, a program works. In python, Comments are started with # symbol see example below. The interpreter ignores the comments.

#this is single line comments

''''' this is

Multiline

Comments ''''' 

Comments is not a part of the program, but it enhances the interactivity of the program and makes the program readable.

Python supports two types of comments:

1) Single Line Comment:

If programmer wants to write a single line comment, then comment must start with #

Example:

# This is single line comment.  

print "Hello Python"  

Output:

Hello Python

2) Multi Line Comment:

If a programmer wants to write multiline comment then it must be starts from triple quotes and ends with triple quotes.

Example:

1.      ''''' This 

2.          Is 

3.          Multiline comment'''  

Example:

1.      #single line comment  

2.      print "Hello Python"  

3.      '''''This is 

4.      multiline comment'''’’’  

Output:

 

Hello Python

Enjoyed this article? Stay informed by joining our newsletter!

Comments

You must be logged in to post a comment.

Related Articles
About Author