Python Function Introduction

Python Functions :

A function is a block of code to perform a specific task. A function consisting a group of statements to represent a specific task. The main objective of a function is to perform a task. If there are multiple tasks to be performed then we will define multiple functions. For example, to display output we write print(), to get current time we write time(), to get the power value, python has power() function. These functions are built in functions. Similarly the programmer can define his own functions which are known as user defined functions.


Why Functions ?

  1. 1. Python Functions processing data and performing task as per the requirement in software development.
  2. 2. Once we write a function that can be reused as per the requirement. That’s why functions are also called as reusable code. Due to the reusability code redundancy is avoiding which is the main advantage. That means we can avoid writing same code again and again.
  3. 3. Python Functions representing modular programming approach. A task is dividing into sub tasks where each sub tasks called as a module. To represent each module we define separate function. Then the functions are called from main program to perform the complete task. This is known as modular programming and it makes programming easy.
  4. 4. In software development, code maintenance is becoming easy due to functions. For example, when a new feature is adding in an existing application, then the new function definition can integrate into the application. If a point is not required then we can delete the corresponding function.
  5. 5. At the time of application development, if any error arises then the corresponding function can update without affecting other functions. Hence code debugging is becoming easy.

Difference between a function and a method

Actually the terminology function and method are same in python. Based on their placement we are saying somewhere is function and somewhere is method.

As we know a function is a block of code to perform a specified task. When a function is calling, then the function definition is executing. When we define a function it becomes a method in generally that we consider.
Method is called as:
Objectname.methodname()
Classname.methodname()


About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc






 PreviousNext