Showing posts with label Python Comments. Show all posts
Showing posts with label Python Comments. Show all posts

Friday, November 15, 2019

Python Comments

• Python Comments



Anything after a # is ignored by Python.
Why comment?

• Describe what is going to happen in a sequence of code.
• Document who wrote the code or other ancillary information.
• Turn off a line of code-perhaps temporarily.

Python supports two types of comments:
1. Single lined comment.
2. Multi lined comment.


1. Single Lined Comment:

In Python, we use the hash (#) symbol to start writing a comment .If developer want to only specify one line comment than use single line comment, then comment must start with #.
Example : 
# This is single line comment. ( hash or pound )
print(“Hello”) #This is notification






2. Multi-line Comments:

If we have comments that extend multiple lines, one way of doing it is to use hash(#) in the beginning of each line.

Example:
#This is a comment
#and it extends
#to multiple

Another way of doing this is to use triple quotes.
These triple quotes are generally used for multi-line strings. But they can be used as multi-line comment as well. Unless they are not docs strings, they do not generate any extra code.

Example:
“”” This is also a
Perfect example of 
Multi-line comments”””