Menu

What is The Difference Between Function and Method in Python?

Difference Between Function and Method in python

Sharing is caring!

Basically, both are ‘Block of Code’ that contains piece of information based on the user’s input. The main purpose of Functions and methods are the ‘Code Reusability’.

Suppose, we are making a code there may be some scenario where some statement can be repeated many number of times which become a problem of complexity. To reduce the complexity in terms of space and time we use the concept of code re-usability. The meaning of code re-usability is to make the set of instructions once in all over the program and use it many number of times as per need to complete the execution instead of re-writing those instructions again and again.

The main functionality of function or methods in terms of python:

  • Function or methods define as-

def Function_name ( ):

Statement_1…

Statement_2….

Statement_n….

  • Function/methods can be call anytime, anywhere inside a program.

Difference Between Function and Method:

Function

  • Functions are basically used for code re-usability.
  • Functions are two types
    • pre-define functions
    • user-define Function
  • Functions can be used inside the class as well as outside of the class.
  • Functions can be controlled by the recursion.
  • Lisp, Java Script, F#, Machine Learning are the pure functional Programming Language.
  • C, C++, Python, .net, C# are the programming language that have the features of the Functional Programming language.

Functions

Methods

  • Methods are similar like the Function and the main task of method is code re-usability as similar like the functions.
  • Methods are always define by the user.
  • Methods are always used the Object Oriented Programming Language.
  • Methods are always defined inside the class.
  • C++, Python, Java, .net, C# are the method based Programming Language.

0 Comment

Leave a Reply

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

shares