Page 95 - 2611_SmartGPT Pro V(5.0) C-8
P. 95
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>
<return statement>
CALLING A FUNCTION
A function can be called anytime from other functions or from the command prompt after the
definition. To call a function, type the function name followed by parentheses. If the function
requires parameters, include them inside the parentheses. For example:
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.
Program1.py
File Edit Format Run Options Window Help
# Function Example
def hello(name):
print("Hello "+name+"! How do you do?")
# Calling Function by passing parameter
hello ('orange')
On running the above program, you will get the following output:
Output
Hello orange! How do you do?
Functions and String in Python 93

