Python

HIGHER ORDER FUNCTIONS

HIGHER ORDER FUNCTIONS

What is a function ?

In programming, there will be many scenarios where we have to use the same code over and over again. So rather than duplicating the code in different parts of your program, you can reuse the code. For this purpose, most programming languages have introduced the concept of functions.

A function is a block of reusable code. A function mainly has two parts: the definition and the function call. The function definition is the area where you define the portion of the code that you want to reuse. The function call is how you reuse the code. What happens during a function call is that, the control will transfer from the function call to the function definition, basically, in simple terms, it will jump from one place to another place.

Function Arguments

Since the function is reusable, there will be parts of the code that will be different during the reusing of the code. We can overcome this problem by using function arguments. Essentially, we will be sending the argument from function call to the function definition, where the function will be using the variables defined in it but the values from the function call.

Higher Order Functions

A higher order function is function will accept or return another function as its argument. This concept is implemented in python as a decorator. A decorator is a wrapper function which can be used to wrap around another function. The advantage of using a decorator is that we can use this feature to compulsorily execute a certain portion of the code. If a function was bypassing a certain segment, we can use decorator to make it go through the same segment it was avoiding.

Another advantage of using decorators comes up when we use it in OOPS, more specifically, in class. We can use it to create functions that will change according to every change in the parent class and so on. It is very clear that the decorator concept is a very important concept that everyone should be familiar with. The training provided by Spectrum Softtech Solutions will make you an expert in python programming.

Author: STEPS

Leave a Reply

Your email address will not be published. Required fields are marked *