Comments are used to explain the code that is written by the programmer so that anyone who wants to read the code cn easily understand that. >>>#This is single line comment >>>print("Hello world!") Hello world! >>>
Comments are most helpful part of any program as they help to understand the way that how a program is actually running or working. So, the comments makes any program more readable and understandable and hence become the importanht part of any program.
In python, comments are written along with the symbol "#". So, any line of code that is starting with the symbol # is considered as a comment and the interpreter does not interpret that.
So, we can say that thogh comments are not the part of any code but then also they play very important role in programmiing as they make the program more readable and understandable and also it enhances the interactivity of the program with the reader.
In python two types of comments are supported:
1) Single Line Comment:
Single line comments are used when the user or the programmer wants to specify only a single line as comment then single line comments are used.
Single line comments are started with the symbol '#' and any line which is starting with the symbol '#' is not interpreted by the interpreter.
>>>#This is single line comment
In the above code the first line is comment and it not the part of the code to be executed.
>>>'''This is multiline comment '''
2) Multi Line Comment:
Multiline comments are used when the user or the programmer wants to specify multilines i.e. more than one line of code as comment then multiline comments are used.
Multiline comments are started with the triple quotes i.e. ''' and any block of lines which is starting with ''' is not interpreted by the interpreter.
With the use of multiline comments we can make more than one lines as comment.
In the above code the lines are comments and they are not the part of the code to be executed.