Friday, December 28, 2018

Python - Comments & Docstring

Comments play a key role while writing any program.It will tell us what the code is going to do.It is mainly used to make the code more readable.

During the development of code ,we need this feature as it will help to deactivate the part of the code that is not in use in the current debugging plan.

Single Line Comment :

#This is an example of single line comment.
#we can give comment like this.


Multi Line Comment :

Multi Line Comment can be given in two different ways :-

By using """ quotes 

""" This is a multi
     line comment using double quotes.
"""

By using ''' quotes

''' This is a multi line
comment using single quote
''' 

Docstring 

Docstring is short for documentation string.It is a string that occurs as the first statement in a module, function, class, or method definition. We must write what a function/class does in the docstring.Triple quotes are used while writing docstrings. For example:


def test(num):
""" to test the divisibility of a number """
.
.
.
return xyz

No comments:

Post a Comment

Hadoop - What is a Job in Hadoop ?

In the field of computer science , a job just means a piece of program and the same rule applies to the Hadoop ecosystem as wel...