The comment is a programmer-readable explanation in the code of a program. In Python script, the symbol #(octothorpe) indicates the start of the comment line. You can define single-line comment as well as multi-line comments.
Python allows you to add comments to your code to make it easier to read. This also helps other programmers in understanding code functions.
Python uses different standards and syntax. This post will show you some practical methods for producing single-line and multiline comments in Python.
When you insert a comment at the end of a line, the Python interpreter will execute the content before the comment and ignore the content following the comment.
How To Add Single Line Comment
You can use #
symbol to define single line comment in python.
#line3 print ("Hello ! Pythonpip")
The # sign was used in the preceding example to comment on the code. The # function only works with a single line of code, not several lines.
Consecutive Single-line Comments in Python
If more than one consecutive line is to be commented, #
symbol must be put at beginning of each line on your python code.
#line1 #line2 #line3 print ("Hello ! Pythonpip")
How To Define MultiLine Comment in Python
A triple quoted multi-line string is also treated as a comment if it is not a docstring of a function or class.
""" comment1 comment2 comment3 """ print ("Hello ! Pythonpip")
One-line docstrings in Python
A one-line docstring is just that: a single line of text. In Python, a one-line docstring starts with triple quotes ("""
) and ends with triple quotes ("""
).
""" simple hello example """ print ("Hello ! Pythonpip")
in the above example, we have used triple-quoted strings to create something that resembles a multiline comment in Python.
is there any demo for that