What are Comments ?
Comments are some statements or some expressions that we write for enhancing the readability of our code and making our program easier to understand. Python interpreter just simply ignore these comments and they doesn't become the part of program. We can simply say that we write them for simplicity and clarity of code.So that we face no problem in understanding them in future and comments also help other people to easily understand your code.
These can be given by simply given by writing :
# followed by the statement that you want to give
eg. # I am a comment and python interpreter will definitely ignore me
eg. print("This is the comments tutorial")
# I am a print statement and this line will not affect your code
2) Multi Line Comment
If we want to give comments in multiple lines then instead
of using # in every line we can use ''' ''' or """ """
eg. ''' I am also a type of comment you can use me also .If
you got bored of using # then you can use me also '''
eg. # This is a comment
# given in more than
# one line
print("We are giving single line comments.")
''' This is a comment
given in more than
one line '''
print("We are giving multi line comments.")
Output: We are giving single line comments.
We are giving multi line comments.
How to give comments in python?
There are basically two types of comments :-
1) Single Line Comment
These are the comments which we give in a single line.These can be given by simply given by writing :
# followed by the statement that you want to give
eg. # I am a comment and python interpreter will definitely ignore me
eg. print("This is the comments tutorial")
# I am a print statement and this line will not affect your code
2) Multi Line Comment
If we want to give comments in multiple lines then instead
of using # in every line we can use ''' ''' or """ """
eg. ''' I am also a type of comment you can use me also .If
you got bored of using # then you can use me also '''
eg. # This is a comment
# given in more than
# one line
print("We are giving single line comments.")
''' This is a comment
given in more than
one line '''
print("We are giving multi line comments.")
Output: We are giving single line comments.
We are giving multi line comments.
Comments
Post a Comment
Please do not enter any spam link in the comment box