Search . . .
Working with
User-Defined
Functions
Session-9
simrantechmentor
Current Stage Search . . .
• Our code is getting complex
• We find it difficult to manage and understand our code.
• In some situation we are writing same code at different
places again and again.
simrantechmentor
Search . . .
Solution :- Functions
A function is a block of code that performs a specific task.
simrantechmentor
Functions- Management of code Search . . .
Function help us to divide a program into smaller chunks that
makes our program easier to understand and manage.
Suppose you have to create a program for bill calculation. You can
create three functions to solve this problem.
• Accept User inputs (Product name, price , quantity)
• Calculate Bill
• Display Receipt
simrantechmentor
Functions- Reusability Search . . .
Once you have created a function you can call it as many times as
you need. You don’t need to write that code again.
For example, you are creating a banking application where you
have implemented code for checking existence of bank account.
You would need this functionality many times in application.
• Before deposit money
• Before withdraw money
• Before approving any service request
simrantechmentor
Type of Functions Search . . .
Standard Library Functions : Built-in functions that are available
to use. For example : print(), input(), randint(), len()
User-defined Functions:- We can create our own functions based on
our requirements.
simrantechmentor
Python Function Syntax Search . . .
simrantechmentor
Implementation Search . . .
Define a Function :- Specify what the function
will do
Call a Function :- Execute functionality
simrantechmentor
Demonstration Function Syntax Search . . .
Program function_syntax.py (Folder In-class Demo) Lab 9
Demonstration Function Sequence Search . . .
Program function_sequence.py (Folder In-class Demo) Lab 9
Demonstration Function Argument Search . . .
Program function_argument.py (Folder In-class Demo) Lab 9
Demonstration Function Argument Search . . .
Program function_argument_2.py (Folder In-class Demo) Lab 9
Demonstration Function Return Value Search . . .
Program function_return_value.py (Folder In-class Demo) Lab 9
Search . . .
THANK YOU
Kindly perform all in class exercise before coming to lab
END SLIDE
simrantechmentor
Contact No : 9878138788
Email : [email protected]