Comments in Python

  Comments in Python

  1. Comments in Python are used to explain the code to make it more readable for the reader.
  2. Comment is not considered as a part of program, in other word we can say that compiler ignores the comment.
  3. Python comments are statements that are not executed by the compiler.
  4. Generally comments are used to tell the user that what we have done in the program so that user can understand it in easy way.

Single line comment

  1. It is used to comment only one line.
  2. Hash symbol(#) is used for single line comment.
  3. In a program if you want to comment only a single line then you can use it otherwise if you you want to comment many lines then you can go for multiline comment.
#this is a single line comment
print("you are excellent");

Multiline comment

  • Multiline comment is used to comment a block of code.
  • Triple quotes (""") are used to comment multiline.
  • Multiline comment starts with """ and ends with """.
  • The text between """ and """ is not executed by the compiler.

"""
This is a multiline comment
Write a program to add two
numbers and stores it into
the third number
"""
x=50
y=30;
z=x + y
print("Sum=",z)
"""
***Output***
Sum= 80
"""