Comments
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. Consider the accompanying code snippet, which
shows how to use a single line comment:
Code
Output:
Code
Output:
Multi-Line Comments
Python does not provide the facility for multi-line comments. However,
there are indeed many ways to create multi-line comments.
Code
1. # it is a
2. # comment
3. # extending to multiple lines
In this case, each line is considered a comment, and they are all omitted.
Code
We can observe that on running this code, there will be no output; thus,
we utilize the strings inside triple quotes(""") as multi-line comments.
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.
Code
Output: