12th Cs ch-3 Working With Functions
12th Cs ch-3 Working With Functions
1) Introduction
2) Understanding Functions
3) Defining Functions in Python
4) Flow of execution in a Function call
5) Passing Parameters
6) Returning value from Functions
7) Composition
8) Scope of variables
9) Mutable/immutable properties of Passed data objects
Function is a collection of statements which is made to perform a specific task.
To Execute function we have to call it in the program.
Instead of writing a large program we can write small functions as a specific part of
program to accomplish the task.
Once written a function can also be used in other programs as library functions
• Functions can be categorized in three types
1. Built-in
2. Modules
3. User Defined
Built-in Functions
• These are the functions which are predefined in python we have to just call them to use.
• Functions make any programming language efficient and provide a structure to language.
• Python has many built-in functions which makes programming easy, fast and efficient.
• They always reside in standard library and we need not to import any module to use them.
Python Modules
• Module is a .py file which contains the definitions of functions and variables.
• Module is a simple python file.
• When we divide a program into modules then each module contains functions and
variables. And each functions is made for a special task.
• Once written code in modules can be used in other programs.
• When we make such functions which may be used in other programs also then we
write them in module.
• We can import those module in any program and we can use the functions.
help Function
• If you forgot that how a library function works then help( ) is very useful for this situation.
• If this function is used with any module then it provides the information and details of the
given module and its all the contents.
string Module
• We have already studied about string module in class XI. Here are
some other functions of string module
random Module
• When we require such numbers which are not known earlier e.g. captcha or any type of serial
numbers then in this situation we need random numbers. And here random module helps us.
This contains following functions-
User-defined Functions
• These are the functions which are made by user as per the requirement of
the user.
• Function is a kind of collection of statements which are written for a specific
task.
• We can use them in any part of our program by calling them.
• def keyword is used to make user defined functions.
Points to Remember…….
Points to Remember…….
Points to Remember…….
RULES FOR FUNCTION
3. BODY OF A FUNCTION CALL ACCORDING TO FUNCTION CALL: loop | if else |input |output
5. FUNCTION CAN RETURN ONE OR MORE THEN ONE VALUE AT A TIME, MULTIPLE