Is Python’s count() a function or a method? It says here that it is a function.
But isn’t it really a method?
Is Python’s count() a function or a method? It says here that it is a function.
But isn’t it really a method?
METHODS | FUNCTIONS |
---|---|
Methods definitions are always present inside a class. | We don’t need a class to define a function. |
Methods are associated with the objects of the class they belong to. | Functions are not associated with any object. |
A method is called ‘on’ an object. We cannot invoke it just by its name | We can invoke a function just by its name. |
Methods can operate on the data of the object they associate with | Functions operate on the data you pass to them as arguments. |
Methods are dependent on the class they belong to. | Functions are independent entities in a program. |
A method requires to have ‘self’ as its first argument. | Functions do not require any ‘self’ argument. They can have zero or more arguments. |
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.