Learn Python comment syntax and How to comment multiple lines in python

Learn how to comment multiple lines in python and python comment syntax with example. Python does have a multiline string/comment syntax in the sense that ... Python tip: You can use multi-line strings as multi-line comments. Writing comment is important in the programming language. Python comment is used to explain the code and used to prevent execution while testing the code. Python comments used as single line python comment. Here we have shown how to comment multiple lines in python language.

Phow to comment multiple lines in python

Creating comments in python:-


1: Single line python comment:-


Here the single line comment is written starting with hash (#) symbol also called octothorpe and extend up to end line but python will ignore it.
Comment should be short, sweet and to the point.
Comments are not executable part in programming but t is important to understand.
Comment that explains the code in an single line is called as single line comment.
e.g.
#this is  single  line comment
print (“Welcome in  World of python”)
O/p:-
Welcome in World of python
The above example has comment in its stamen but after execution python will ignore the comment.


2: Multiple line comment in Python:-

They are written on top with the author’s information.
The comment which explains the code in multiple lines is called as multiline comment.
Multiline comment start with “””and end with “”” also by triple quotes anything written between it can be ignored by compiler.
As you write multiline comment in java we do not have way to write comment in python.

e.g:
“””This is multiline comment which can be in more than one line”””


    Print (“Hello”)
O/p:
    Hello
The above example shows that the comment written in triple quotation is ignored.
Two ways of multiline comments:-

  1. Python Block comment:-

Manny single line comment are used to run the block
Writing real comment that span across multiple lines.
It is supported and preferred by python PEP style guide because comments are ignored by python interpreter.
In spite of writing comment in quotation you can write in # in front of each line.
e.g. 
#Multiline commenting way
#in python
If you have paragraphs in comment you can write as follows
e.g. 
#multiple commenting way
#
#in python

  1. Using Docstrings:-

It string should begin with capital letters and end with period.
           Docstrings are used as multiline comment by programmers.
         There is scientific difference between comments and docstrings.
          Comments in python are ignored while Docstrings used inside python function can    be accessed at runtime.
         DocString can be accessed by   “_doc_ “method or help function.

Additional Services : Refurbished Laptops Sales, Python Classes, Share Market Classes And SEO Freelancer in Pune, India