Comments in Python
Comments in Python
Topperworld.in
Comments
• Comments in Python are the lines in the code that are ignored by the
interpreter during the execution of the program.
• Comments enhance the readability of the code and help the programmers
to understand the code very carefully.
❖ Types of Comments
There are three types of comments in Python:
o Single line Comments
o Multiline Comments
o Docstring Comments
❖ Single-Line Comments
• Single-line remarks in Python have shown to be effective for providing
quick descriptions for parameters, function definitions, and expressions.
• A single-line comment of Python is the one that has a hashtag # at the
beginning of it and continues until the finish of the line.
• If the comment continues to the next line, add a hashtag to the
subsequent line and resume the conversation.
Example:
Output:
©Topperworld
Python Programming
❖ Multi-Line Comments
Python does not provide the facility for multi-line comments. However,
there are indeed many ways to create multi-line comments.
1. # it is a
2. # comment
# extending to multiple lines
❖ Python Docstring
• The strings enclosed in triple quotes that come immediately after the
defined function are called Python docstring.
• It's designed to link documentation developed for Python modules,
methods, classes, and functions together.
• It's placed just beneath the function, module, or class to explain what they
perform. The docstring is then readily accessible in Python using the
__doc__ attribute.
©Topperworld
Python Programming
Example:
Output:
This function adds the values of x and y
©Topperworld