A bound method is the one which is dependent on the instance of the class as the first argument. It passes the instance as the first argument which is used to access the variables and functions. In Python 3 and newer versions of python, all functions in the class are by default bound methods.
Let’s understand this concept with an example:
< bound method A.func of <__main__.A object at 0x7fb81c5a09e8>>
obj.func(arg) is translated by python as A.func(obj, arg).
obj is automatically passed as the first argument to the function called and hence the first parameter of the function will be used to access the variables/functions of the object.
Let’s see another example of the Bound method.
Car1 gears before calling change_gears() = 5 Gears after calling change_gears() = 6 <bound method Car.change_gears of <class '__main__.Car'>>
The above code is an example of a classmethod. A class method is like a bound method except that the class of the instance is passed as an argument rather than the instance itself. Here in the above example when we call
Car1.change_gears(6), the class ‘Car’ is passed as the first argument.
- Bound, unbound, and static methods in Python
- Private Methods in Python
- List methods in Python
- List Methods in Python | Set 1 (in, not in, len(), min(), max()...)
- Element methods in Selenium Python
- Accessor and Mutator methods in Python
- Dictionary Methods in Python | Set 1 (cmp(), len(), items()...)
- Methods of Ordered Dictionary in Python
- Response Methods - Python requests
- Web Driver Methods in Selenium Python
- Python | Float type and its methods
- Accessing Attributes and Methods in Python
- Dunder or magic methods in Python
- Http Request methods - Python requests
- Python | Implementing 3D Vectors using dunder methods
- Python Input Methods for Competitive Programming
- Analysis of Different Methods to find Prime Number in Python
- Dictionary Methods in Python | Set 2 (update(), has_key(), fromkeys()...)
- Customize your Python class with Magic or Dunder methods
- List Methods in Python | Set 2 (del, remove(), sort(), insert(), pop(), extend()...)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.