Page 1 - LN
P. 1

Lesson Note


                                           Computer Science

                                                     Class - XII

                                 Chapter – Working with Functions



               Functions
               Functions provide a systematic way of problem solving by dividing the given task into several
               subtask, finding their individual solution, and integrating the solutions of individual task to solve the
               original problem.
               Functions can be reused
               It makes the program more readable, understandable and makes program management easier.

               Python has three types of functions:
                  i)   Built-in functions
                 ii)   Functions defined in Modules
                 iii)   User-defined functions


               Built In Functions
               These are predefined functions already available in Python. These are always available in standard
               library and we don’t have to import any module/file for using them.
               Some of the built in functions are: print(), id(), max(), len(), str(), bool(), ord() etc


               Modules
               As you start to write bigger programs, you'll want to keep the procedure definitions in multiple files,
               grouped together according to what they do. So, for example, you might package a set of utility
               functions together into a single file, called utility.py. This file is called a module in Python.
               Now, if there is a need to use those procedures in another file, or from the the Python shell, just
               write/execute the command
               import utility
               Now, if there is a procedure in that file called sample, to use that in other program command is
               utility.sample

               User Defined Function

               Function defined/created by user
               Syntax for a user defined function is:
               def  function_name (comma separated list of parameters):
                       statement1
                       statement2
                       ….
                       return (optional)


               Program without a return statement and not returning any value
   1   2   3   4   5   6