A function is a block of organized, self-contained programs that perform a specific task, which you can incorporate into your own larger programs. They are defined as follows:
# function
def functionname():
do something
return
These are a few points to remember:
Indentation is very important in Python programs
By default, parameters have a positional behavior, and you need to inform them in the same order that they were defined in
Please see the following code snippet example, which showcases functions:
def display ( name ):
#This prints a passed string into this function
print ("Hello" + name)
return;
You can call the preceding function as follows:
display("Manish")
display("Mohit")
The following screenshot shows the execution of the preceding display function:
Note that if you have more than one Python version installed on your system, you need to use Python 3 instead of Python, which uses the default version of Python (generally, 2.7.x).