Page 54 - Modular v1.1 Pyhton
P. 54

CREATING A FUNCTION

                  We can create a function in the following steps:

                      Defining a Function: We use the def keyword to begin the function definition.
                      Naming a Function: Provide a meaningful name to your function.

                      Supply Parameters: The parameters (separated by commas) are given in the parenthesis
                      following the name of the function. These are basically the input values we pass to the function.

                      Body of the function: The body of the function contains Python statements that make our
                      function perform the required task. Syntax of creating a function is:

                      def < name of the function > (list of parameters)
                              <body>


                      CALLING A FUNCTION

                  A function can be called anytime from other functions or from the command prompt after the
                  definition. For calling a function, we type the function and pass the parameters. For example:

                  To call a function.


                                 def my_function( ):                                 Name of a function


                                       print (“Hello”)                                Body of a function



                                 my_function( )                                        Function call


                  Program 1: To add two numbers using all the three types of built-in functions.


































                   52     Touchpad MODULAR (Version 1.0)
   49   50   51   52   53   54   55   56   57   58   59