Skip to main content

Python: Bound, Unbound, and Static Methods

Bound Methods

In Python, if a function is an attribute of class and it is accessed via the instances, they are called bound methods.

The methods with the “self” argument at the beginning are the bound methods. Since these are dependent on the instance of classes, these are also known as instance methods.

It  is the one which is dependent on the instance of the class as the first argument of that particular class. It passes the instance of the class as the first argument which is used to access the variables and functions. 

Example:

class Fruit :
    def func(self):
        print('Fruit is good for Health')
        
apple = Fruit()
apple.func()

Output: Fruit is good for Health

Unbound Method

It is essentially a function with some trimmings.Methods that do not have an instance of the class as the first argument are known as unbound methods. They are not bounded with any specific object of the class.

We cannot call this method using a class instance.

Static Methods are examples of unbound methods

Static Methods

It is similar to class methods but are bound completely to class instead of particular objects.Staticmethods are those methods which are not bound to the class instance and deal only with the arguments it takes.

It is accessed using class name.

Example:

class Fruit:
    def func():
        print('Fruit is good for Health')

Fruit.func()

Output: Fruit is good for Health

Tags
Submitted by devanshi.srivastava on July 19, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.