Skip to content

Importance of Function In Programming

  • by
importance of function in programming 321


In programming, the use of function is one of the means to achieve modularity and reusability. Function can be defined as a named group of instructions that accomplish a specific task when it is invoked. Once defined, a function can be called repeatedly from different places of the program without writing all the codes of that function everytime, or it can be called from inside another function, by simply writing the name of the function and passing the required parameters. The programmer can define as many functions as desired while writing the code. The program 7-1 is rewritten using user defined functions.

Suppose in further the company decides to design another type of tent whose base is rectangular, while the upper part remains the same. In such a scenario, some part of the existing code can be reused by calling the function con(l,r). If the company develops other products or provides services, and where 18% tax rate is to be applied, the programmer can use the function post_tax_price(cost)directly. Thus, following are the advantages of using functions in a program: 

• Increases readability, particularly for longer code as by using functions, the program is better organised and easy to understand. 

• Reduces code length as same code is not required to be written at multiple places in a program. This also makes debugging easier. 

• Increases reusability, as function can be called from another function or another program. Thus, we can reuse or build upon already defined functions and avoid repetitions of writing the same piece of code. 

• Work can be easily divided among team members and completed in parallel.


Taking advantage of reusability feature of functions, there is a large number of functions already available in Python under standard library . We can directly call these functions in our program without defining them. However, in addition to the standard library functions, we can define our own functions while writing the program. Such functions are called user defined functions. Thus, a function defined to achieve some task as per the programmer’s requirement is called a user defined function.

Creating User Defined Function

The items enclosed in “[ ]” are called parameters and they are optional. Hence, a function may or may not have parameters. Also, a function may or may not return a value. 

• Function header always ends with a colon (:). 

• Function name should be unique. Rules for naming identifiers also applies for function naming. 

• The statements outside the function indentation are not considered as part of the function.

Arguments and Parameters

 In the above example, the numbers were accepted from the user within the function itself, but it is also possible for a user defined function to receive values at the time of being called. An argument is a value passed to the function during the function call which is received in corresponding parameter defined in function header.

Leave a Reply

Your email address will not be published.