Comments are non-executable statements in Python. It means neither the python compiler nor the PVM will execute them. Comments are intended for human understanding, not for the compiler or PVM. Therefore they are called non-executable statements.
There are two types of commenting features available in Python: These are single-line comments and multi-line comments.
A single-line comment begins with a hash (#) symbol and is useful in mentioning that the whole line should be considered as a comment until the end of the line.
#Defining a variable to store number. n = 50 #Store 50 as value into variable n.
- In the above example program, the first line starts with the hash symbol, so the entire line is considered a comment.
- In the second line of code, "N = 50" is a statement, and after the statement, the comment begins with the # symbol. From the # symbol to the end of this line, the line will be treated as a comment.
Triple double coat (""") and single coat (''') are actually docstrings, which are also used as comments. The key usage of docstrings is explained in the Python API Documentation chapter, and we will learn more about it in the further chapters.
Multi-line comment is useful when we need to comment on many lines. You can also use a single-line comment, but using a multi-line instead of single-line comment is easy to comment on multiple lines.
In Python Triple double quote (""") and single quote (''') are used for Multi-line commenting. It is used at the beginning and end of the block to comment on the entire block. Hence it is also called block comments.
""" Author: www.w3schools.in Description: Writes the words Hello World on the screen """
''' Author: www.w3schools.in Description: Writes the words Hello World on the screen '''