Thursday, 21 July 2016

Functions in Python

Function is a block of code , which is reusable code that is used to perform a single related action. Function break our program into chunks . Our program grows larger and larger, functions make it more organized and easy to undersatnd . Function provide  a high degree of code reusing .

Kindly find the below syntax for declaring dunctions in python:

def  test(parameter):
     “““docstring”””
     statement(s)

Find the below given function definition  of above declartion of function

1.  def , this is a keyword which is used to declaring a function

2.  test,   this is  the function name .

3.   A colon (:)  to  mark the end of function header .

4.   within the triple quotes(“””  “””) we define the docstring . This is optional documention string(docstring)  to explain what your function exactly does .

5.  statement can be one or more which make up the function body . Statement should also have same indentation level (defaul is as 4 spaces).

#  For example ..

def test():
    “”” This function work is to print a simple string “
    print “ Welcome to python world “


*  when we declare a function and  if we want to see the output exactly what this function is doing then we have need to call that function .

Syntax:

functionname()

like if we want to call above function called as test .
test()

>> Welcome to python world
softcrayons tech solutions offers python training with free demo class.

No comments:

Post a Comment