Table of Contents
Python programming language functions
In this tutorial, we will discuss the concept of Python programming language functions.
In python, function is a collection of related and reusable statements include as a single unit. This is used to perform a specific action that looks like a method.
Basically two type of functions are available in python.
1. Built-in function – this functions defines and it is a built-in python programming language.
For Examples – Math function, String function
2. User- defined function – Users can define the function themselves.
This tutorial explains user defined functions
The advantages of using functions are:
- clearly understanding code
- reducing duplication in code
- reuse of code
- Information hiding
Syntax of python function
- A function created with the def keyword in python that is used to identify the start of the function.
- function_name is used to uniquely identify every function.
- Parameters and arguments are used to pass variables and values to function but parameter passing is optional (it is not compulsory).
- A colon mark is used to identify the end of the function.
Example of function
We can demonstrate about python function usingthe following examples
Program 1
How to create simple “hello world” program using python function
Program 2
Program 3
When the above code was executed, it produced the following results
hello i am a function
Program 4
hello kanthan
hello Nimal
hello Santhan
Program 5
The return ststement