Introduction
In this article, the focus of the content is still discussing about some feature available in Python programming language. One of those feature is the utility of the function. So, this article will discuss about how to use the function in Python programming language. Generally, before going on further there is a definition of the function. As a simple definition, function is a collection of statements or line of codes which is joined into a single unity as a block of code. Those single unity of block code can be executed or used multiple times.
Basically, function in Python programming language can receive parameters. Furthermore, it can return value and it can be executed multiple times independently. The purpose of having a function is to divide larger written program into several smaller written program with its own specific tasks. Having several smaller written program in the form of several smaller function will make it more reusable and structured.
Function Characteristics in Python
In this part, the content will be focusing on the characteristics of the function in Python programming language. So, below are the characteristics of functions in Python programming language :
-
First of all, function in Python programming language starts with ‘def’ reserved keyword.
-
Next, the ‘def’ reserved keyword must be followed with the name for the function. The name of the function itself is also following the rule, standard and convention for variable name. Just read the article describing it in this link with the title of ‘Variable in Python’.
-
Following after the name, add another additional character which is opening and closing brackets. Furthermore, as an optional addition, there can be a parameter inside the opening and closing brackets. The parameter inside the opening and closing brackets is not mandatory and it is more like an optional choice. It depends on the requirement or the need whether to have it or not.
-
After that, do not forget to end it with a double colon. It acts as the start or the beginning for the statement collections definition for the function.
-
Finally, just define all the necessary collection of statements which is defining all processes execution which is going to be represented by only executing the function.
Using the above descriptions as the characteristics of function in Python programming language, actually, it is very simple for having a function in Python programming language. The following is the simple pattern for defining function in Python programming language :
def function_name(parameter): statement_1; statement_2; statement_3;
One thought on “Function in Python”