Page 103 - Computer - 8
P. 103
8 Functions, Strings, and
Lists in Python
Pre-Processing
• Functions in Python • Features of Functions
• Components of a Python Function • Types of Functions in Python
• Creating a Function • Calling a Function
• Working with Strings • Working with Lists
You have learned about Problem solving. It involves breaking down a complex problem into smaller and
simpler steps. This also helps in organising the steps for a task in an orderly manner. In the similar way,
a complex and large program can be broken down into simpler and manageable parts of codes called
modules. One type of programming modules is called Functions.
FUNCTIONS IN PYTHON
A Function is a code block that has a name and can be reused anywhere in a program. A function
performs a specific task. It can be used in a program by simply using its name. The print( ) and input( ) are
examples of functions that you have already used in various programs in Python. The print( ) function
is used to display messages and values, while the input( ) function is used to accept data from the user.
FEATURES OF FUNCTIONS
Functions are the basic components of a procedural programming language. Some important features
of functions are:
1. Modularity: Functions let us divide a large, complex program into small parts called modules. This
helps in keeping the code organised and easy to make changes in it.
2. Reusability: A function can be used as many times as required in a program. This saves time
and effort of writing the same code repeatedly. It also helps reduce the length of a program.
A library of functions enables us to use the functions stored in the library in any program.
3. Easy Debugging: It is easy to track errors in a program and correct them when it is divided into
smaller, manageable segments.
COMPONENTS OF A PYTHON FUNCTION
A Python program is made up of the following components:
• Function Name: A function is given a name that is unique and related to its purpose. This allows
us to create multiple functions with different set of arguments.
• Arguments: The values given as input to the function are called Arguments. A function may or
may not have any arguments.
• Body of Function: It consists of all the executable statements that are used to perform the task of
the function.
• Return Expression: A function may or may not return a value as output. If it does return a value,
the Return statement is used to specify the expression or value.
101