Python Comments
In programming languages, comments are inline non executable statements that are made to explain the functionality of methods, classes, variables or to inform other developers who will interact with the code in future on areas they should be careful while handling code changes.
It is a good practice to comment our code because it helps in reducing the cost of maintaining the program in future as the developers in future will not have to take a lot of time understanding the program.
In python comments are preceded by the # symbol. Any code/text after the # will be ignored.
Single Line comments
# is at start of the comment sentence
Example
When the above program is run, the output is as below
Multi line comments
To write comments that span multiple lines in Python,
we place the # symbol at beginning of every line
Example
#multi line comments
#name hold the person's name
#dob is the date of birth
#age in years
When the above program is run, the output is as below
Multi line comments using String literals
Enclose your multi line comment string within triple double quotes (""")or triple single quotes(''').Python ignores such un assigned string literals and in essence they serve as multi line comments.
Example
"""
multi line comments - 2
name hold the person's name
dob is the date of birth
age in years
"""
When the above program is run, output is as below