A comment is a statement which is not executed by the interpretor. It's simply avoided by the interpretor.
A single-line comment can be implemeted by using a #
(hashtag) symbol.
# A python program to show implementation of a single-line comment
# This is a single line comment
A multi-line comment can be implemeted by using a ''' '''
symbol.
'''A python program to show implementation of a multi-line comment
This is a multi-line comment'''
A comment can also be written alongside a statement to write its explanation etc.
x = 5
print(str(x)) # printing 'x' as a string rather than an integer
- Adding what the program is about
- Adding explanatory note of a source code
- Comment a part of the code during testing
- Adding a plan regarding the design of a source code