Python Comments

Comments in Python begin with a hash mark (#) and whitespace character and continue to the end of the line.

Generally, comments will look something like this:



    #This is a Comment


Because comments do not execute, when you run a program you will not see any indication of the comment there. Comments are in the source code for humans to read, not for computers to execute.


advertisement

1) Single lined comment:

In case user wants to specify a single line comment, then comment must start with #.



# This is single line comment.


advertisement

2) Multi lined Comment:

Multi lined comment can be given inside triple quotes.





#single line comment
print "Hello Python"
'''''This is
multiline comment'''



advertisement

3) inline comments

If a comment is placed on the same line as a statement, it is called an inline comment. Similar to the block comment, an inline comment begins with a single hash (#) sign and followed by a space and comment.

It is recommended that an inline comment should separate from the statement at least two spaces. The following example demonstrates an inline comment



n+=1  #increase n by 1


advertisement