In this lesson, we’ll look at different approaches for “Commenting a Python Code”.
Comments are the user-defined statements that do not effect the normal flow of execution of a program rather are defined to increase the readability and understandability of a program. In Python programming, comments are defined with the help of ‘ # ‘. Comments are generally ignored by the interpreter.
There are two approaches for commenting a python code :
1. Single-Line Comment : These comments start with a ‘#‘ symbol
For instance, let us consider the following code :
a=10 b=20 # storing the sum value in variable c. c = a+b print(c)
This code will print the sum of two numbers(a,b) i.e 30. In the above code, line 3 (s3) is acting as a comment it will not have any effect on program’s execution.
2. Multi-Line Comment : In multi-line comments, we use ”’ (triple quotes) or ” (double quotes) in the beginning as well as the ending of the block.
This code will print nothing as we have commented statements s3 & s4.
a=10 b=20 '''c = a+b print(c)'''