menu search
brightness_auto
more_vert
2 1

What are the comments in python? List down the various types of comments.

Topic Python Programming
Type Short Answer Type
Class 10
thumb_up_off_alt 2 like thumb_down_off_alt 0 dislike

1 Answer

more_vert
 
verified
Verified Answer
1

Comments are the piece of code that is generally ignored by the Interpreter, it helps the programmer to keep track of the code, organize it properly, and Maintain the code collectively in a team.

It’s helpful and considered good practice to comment on your code because

There are 2 types of comments in Python:

  • Single Line Comments 
  • Multiline Comments.

Single Line Comments in Python: 

Single-Line Comments
In python single comments are denoted by “#”, like the example given below. The interpreter ignores all the text after #

#this line is a comment

print('Hello') # anything after hash is a comment like this
Multiline Comments in Python:

 

Here, the multiline string isn’t assigned to any variable, so it is ignored by the interpreter. Even though it is not technically a multiline comment, it can be used as one. 
'''
I am a
multiline comment!
'''
print("Hello World!")

"""
I am a also
multiline comment!
"""
thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike

Related questions

thumb_up_off_alt 3 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 3 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 2 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 3 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 3 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 3 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 2 like thumb_down_off_alt 0 dislike
1 answer
...