2018/09/24

Difference between Method and Function in Python

Python Method
  1. Method is called by its name, but it is associated to an object (dependent).
  2. A method is implicitly passed the object on which it is invoked.
  3. It may or may not return any data.
  4. A method can operate on the data (instance variables) that is contained by the corresponding class  
Functions
  1. Function is block of code that is also called by its name. (independent)
  2. The function can have different parameters or may not have any at all. If any data (parameters) are passed, they are passed explicitly.
  3. It may or may not return any data.
  4. Function does not deal with Class and its instance concept. 
Difference between method and function
  1. Simply, function and method both look similar as they perform in almost similar way, but the key difference is the concept of ‘Class and its Object‘.
  2. Functions can be called only by its name, as it is defined independently. But methods can’t be called by its name only, we need to invoke the class by a reference of that class in which it is defined, i.e. method is defined within a class and hence they are dependent on that class.