Methods and Functions are appear likely to be similar when you see them but have key differences in what they actually are. In a nutshell, both methods and functions perform tasks and may return some value. But the difference lies in the fact that methods are ‘associated’ with objects, while functions are not.
METHODS :
1)Methods definitions are always present inside a class.
2) Methods are associated with the objects of the class they belong to.
3) A method is called ‘on’ an object. We cannot invoke it just by its name.
4) Methods can operate on the data of the object they associate with.
5) Methods are dependent on the class they belong to.
6) A method requires to have ‘self’ as its first argument.
FUNCTIONS :
1) We don’t need a class to define a function.
2) Functions are not associated with any object.
3) We can invoke a function just by its name.
4) Functions operate on the data you pass to them as arguments.
5) Functions are independent entities in a program.
6) Functions do not require any ‘self’ argument. They can have zero or more arguments.
Methods and Functions are appear likely to be similar when you see them but have key differences in what they actually are. In a nutshell, both methods and functions perform tasks and may return some value. But the difference lies in the fact that methods are ‘associated’ with objects, while functions are not.
METHODS :
1) Methods definitions are always present inside a class.
2) Methods are associated with the objects of the class they belong to.
3) A method is called ‘on’ an object. We cannot invoke it just by its name.
4) Methods can operate on the data of the object they associate with.
5) Methods are dependent on the class they belong to.
6) A method requires to have ‘self’ as its first argument.
FUNCTIONS :
1) We don’t need a class to define a function.
2) Functions are not associated with any object.
3) We can invoke a function just by its name.
4) Functions operate on the data you pass to them as arguments.
5) Functions are independent entities in a program.
6) Functions do not require any ‘self’ argument. They can have zero or more arguments.