After reading this Python comments topic, you will understand why we write comments and how to write comments on one line or on multi-line in Python.
Python comments are included by the user for some documentation or explanation. This Python comment is greatly useful to other users to understand the logic of the program. Python comments can be inserted either on one line or on multi-line and when user insert these comments will be ignored by Python interpreter.
Comments on One Line
The comments on one line mean any text written after the hash (i.e. #) symbol on the same line will be ignored by Python.
Example:
Program (1): To demonstrate how to insert one line comment in Python.
#to print text and this line is comment print("Python Programming")
Output(1)
Python Programming
Comments on Multi-Line
Use triple quotes (i.e.”””) for writing multi-line comments. The comments on multi-line mean text written for any number of lines within “”” and “”” will be ignored by JavaScript.
Example:
Program (1): To demonstrate how to insert multi-line comments in Python.
""" In this topic we are going to discuss how to write multi-line comment in Python and this comment generally ignore by Python """ print("Python Programming")
Output(1)
Python Programming