Python Comments:

Single Line Comments in Python:

Python has commenting capability for the purpose of in-code documentation.Comments can be used to explain Python code.Comments are often wont to make the code more readable. comments are often wont to prevent execution when testing code.

A hash symbol (#) that is not inside a string literal will act as python single line comment.

All characters after the # and up to the top of the physical line are a part of the comment and therefore the Python interpreter ignores them.

print "Hello, Python!" # This is single line comment in python

Multi Line Comments:

Python doesn’t really have a syntax for multi line comments. To add a multi- line comment you could insert a # for each line.

# This is a comment.
# This is a comment, too.
# This is a comment, too.
# I said that already.

Since Python will ignore string literals that are not assigned to a variable, you can add a multi line string (triple quotes) in your code, and place your comment inside it.

This is a multiline

As long as the string is not assigned to a variable, Python will read the code, but then ignore it, and you have made a multi line comment. Now, lets move forward to Python Variables and types in the next tutorial.

Learn More:

%d bloggers like this: