Comments in python


 

Comments in python


  • The comments are the statement in the code which are ignored by the python interpreter. 
  • Comments are used to add additional information about the program and the statement to understand by the people.
  • Comment can written anywhere in the program and it is good to write comments in code.
  • The comments in python begin with the # (Hash) character. 
  • Anything written in the # is considered as single line comment in a python.
  •  # This is the comment in python.

Types of comment : In python there are two types of comments .

1.Single-line comments.

2. Multi-line comments.

Single-line comments : The single line comments start with the # character.it can write inline with code and also in an individual line.

Example : 

# the print() function use to print message on the screen or output device 

print("Comment in the python") 

output : Comment in python

we see the one more example

a=2 # value of a is integer

b=2.5 # Value of b is float

c= a + b # addition of a and b

print(c)

output : 4.5

Multi-line comments :   Multi-line comment are used for large text descriptions of code unlike other programming language python does not support the multi-line comments blocks out of the box.

To use multi-line comment in code use # for each line.

Example : 

#This is multi-line comment

#write in more than one line

#print("Multi-line comment")

print("Multi-line comment")

Output : Multi-line comment

To use Multi-line string in python we use triple quotes or single triple quotes at start and end of the comment.

"""This is multi-line comment

write in more than one line"""

print("Multi-line comment")

Output : Multi-line comment

Conclusion : It always good to write a comments in code It helps us to understand the code at the time when we revisit the code we hope you understand about the comments in python it easier for you to create comment while coding.


Comments

Post a Comment

Popular posts from this blog

Assignment Operators in Python

Installation Of Python