When you are writing a program it is necessary that your program is easily readable and understood by others. An easy way to increase readability of the program is to use comments.
There are mainly two ways to write comment in python.
- Single line comment
- Multiline comment
Single line comment:-
Single line comment is to include comments that detail or indicate the section of the code. To write a comment we have to use ‘#’ before the sentence.
#This is a comment print("Hello, world!")
Python interpreter ignores whatever written after hash.
Multiline comment are paragraph that serve as documentation for others reading your code easily. In this comment we have to use ‘#’ before every line of the paragraph.
#This is a multiline comment #Example is given. #A hello world program. print("Hello, world!")
There is one more thing which we can use as comment known as Docstring. The sentence is written in triple quotes. If it is written before code it will not be back in output but if it is written after code it will be back in output.
""" Docstring""" print("Hello, world!")