Page 154 - Plus_V2.2_C8_Flipbook
P. 154
Let us understand this with the help of an example:
Program 8: To add two numbers using all the three types of user-defined functions.
You will get the following output:
Creating a Function
We can create a function in the following ways:
Defining a Function: We use the def keyword to begin the function definition.
Naming a Function: Provide a meaningful name to your function.
Supply Parameters: The parameters (separated by commas) are given in the parenthesis following
the name of the function. These are basically the input values we pass to the function.
Body of the function: The body of the function contains Python statements that make our function
perform the required task. Syntax of creating a function is:
def < name of the function > (list of parameters)
<body>
Calling a Function
A function can be called anytime from other functions or from the command prompt after the
definition. For calling a function, we type the function and pass the parameters.
152 Premium Edition-VIII

