In programming languages, comment lines are used to explain the code. In python, we use python comment code or python comment syntax for this purpose. To do this, we use “#” sign.
Python comment syntax uses “#” at the beginning to explain anything in a line. Beside this sign, we can also use “triple quotes” to create comment lines.
The comments are not printed in the output screen. They are only informative lines to inform coder or programmer about the code or lines.
One of the ways to create comment lines, we use “#” sign.The lines that we use this sign at the beginning, will not be in output. Because, they are the lines that inform the python coder.
In the below Python Comment code example, you can see how to sue “#” sign for comments.
As you can see below, the comments lines are not seen in the output.
You can also watch the video of this lesson!
Another way to create comment lines, we use “triple quotes”. Python do not ignore the string that are not assigned to a variable. So, this technique is also used as python comment syntax. Such lines are called “Docstrings”.
Below, you can find an example of how to use “triple quotes” for python comments.
The output will be:
In this lesson, we have learned how to create comment lines in python. You can sue python comment syntax in your codes to explain the code to yourself or to the other python programmer. These are very useful line for python coders. You can use both “#” sign and triple quotes for comments. The result of both of them will be the same.