Comments are the non-executable statements in a program. In Python, they are added to describe the statements. It makes the program easily readable and understandable. Actually, the interpreter ignores the comments.
Comments start with a #. All the characters following the # and up to the end of the line are part of the comment.
A program can have any number of comments.
Python Comments Example
The following program is to use a single line comment. Here sqrt() is using to return the square root of 5, and the import statement is using to import the math module.
#write a program to display the square root of number import math a=int(input("Enter the value=")) b=math.sqrt(a) print("The square root is=",b)
Output:
Enter the value=5
The square root is= 2.23606797749979
In Python, there is no syntax for multiline comments. When we want to add a multiline comment in Python, we insert a # for each line.
Now we are giving an example for using a multiline comment.
#Taking values from the user #Adding them #Printing the result a=int(input("Enter the first value=")) b=int(input("Enter the second value=")) c=a+b print(c)
Output:
Enter the first value=90
Enter the second value=80
170
Leave a comment