Header Ads

Header ADS

Comments in Python


Comments in Python

Comments are the most common thing on all computer language.
Comment is a part of code which is ignored by the compiler or interpreter.
mostly comments are written before declaring/ defining a variable or function to show for what this variable / function is used.

Comments in python begin with a hash mark ( # ) and continue to the end of line.
as comments are ignored by compilers or in our case interpreter so they don't even execute with in other program code.

because comments do not execute, when you run a program you will not see any indication of the comments there.

Comments are in the source code for human to read, not for computers to execute. 

Types of comments in python.

 Their are 2 types of comment in python 

1. single line comment :

single line comment are started with # and end with the end of line.
Single line comments are also called as block comment.

Code to illustrate:
       			 
# this is a comment
print("This will printed after comment")

 
OUTPUT :

This will printed after comment

basically comments are used for programmer by programmer for easily understand the code.
like :
sum = a+b  #  sum variable stores the addition of a and b variable
This is a example of inline comment.



2. multiline comments :

multiline comments does not use # symbol.The multiline comment are given inside triple quotes.

Code to illustrate:
       			 
print(" Welcome to dynamic Coding")
''' This will print
welcome to dynamic coding'''

 
OUTPUT :

Welcome to dynamic Coding


Note :  you can use single quote as well as Double quote.




Inline comment :

if a comment is placed on the same line as a statement, it is called as an inline comment. Similar to the block comment, an inline comment begins with a single hash
( # ) symbol and followed by  spaces and your message/ comment

It is recommended  that their must be 2 spaces between ( # ) hash symbol and 
message/ comment .

Code to illustrate :

n += 1 #  increase n by 1






Thanks for Visiting here.
If you have any doubts and feedback please comment , we will try to reply you as fast as we can.

No comments

Powered by Blogger.