Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
31 views14 pages

Session 9 Working With User Defined Functions

This document discusses user-defined functions in Python. It explains that functions help manage complex code by dividing a program into smaller, reusable chunks. User-defined functions can be created to perform specific tasks and are defined using a function syntax of defining the function name, parameters, and code block. Functions make code easier to understand, manage, and reuse by allowing code to be called repeatedly without rewriting it. Examples demonstrate defining, calling, and using arguments and return values in functions.

Uploaded by

parth280704
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views14 pages

Session 9 Working With User Defined Functions

This document discusses user-defined functions in Python. It explains that functions help manage complex code by dividing a program into smaller, reusable chunks. User-defined functions can be created to perform specific tasks and are defined using a function syntax of defining the function name, parameters, and code block. Functions make code easier to understand, manage, and reuse by allowing code to be called repeatedly without rewriting it. Examples demonstrate defining, calling, and using arguments and return values in functions.

Uploaded by

parth280704
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

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]

You might also like