Page 113 - Plus V4 with Adobe class 8
P. 113
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 name and pass the parameters. For example:
To call a function
def my_function(): Name of a function
print (“Hello”) Body of a function
my_function() Function call
Program 1: To print a string by calling a function
You will get the following output:
#Functions and String in Python 111

