Functions and Local-Global Variables2
Functions and Local-Global Variables2
GLOBAL VARIABLES
Vaisakh M Nair
Mtech Biomedical Engineering
FUNCTIONS
• In Python, a function is a block of code that performs a specific task and can be called
multiple times from anywhere in a program.
• The idea is to put some commonly or repeatedly done tasks together and make a
function so that instead of writing the same code again and again for different inputs.
• Types of Functions in Python:
• Built-in library function: These are Standard functions in Python that are available
to use.
• User-defined function: We can create our own functions based on our
requirements.
EXAMPLE PROBLEM FOR FUNCTION
• Write a code for checking whether the number is even or odd using function
and formatting
• Find the largest of 2 numbers using function
• Sum of number in a list using for loop and function
BUILD IN FUNCTIONS(DATA CONVERSION)
• These are the functions that you create yourself to perform different tasks
• These functions allows you to organize code into reusable blocks, improving
readability and reducing repitition
FUNCTION WITH PARAMETERS
USER DEFINED FUNCTION WITH MULTIPLE
VALUE
USER DEFINED FUNCTION THAT RETURNS
MULTIPLE VALUES
RECURSIVE FUNCTION(USERDEFINED)
• Recursive function: it is a function that repeats or uses its own previous term
to calculate subsequent terms and thus forms a sequence of terms.
NESTED FUNCTION
NESTED FUNCTION WITH MULTIPLE
LEVELS