In Python, class is a prototype for objects which is a user-defined type. It specifies and defines objects of the same type, a class includes a cluster of data and method definitions. Moreover, an object is a single instance of a class but you can create many objects from a single class.
Note: For more information, refer to Python Classes and Objects
Accessor and Mutator methods
So, you all must be acquainted with the fact that the internal data of an object must be kept private. But there should be some methods in the class interface that can permit the user of an object to access and alter the data (that is stored internally) in a calm manner. Therefore, for that case we have two methods namely Accessors and Mutators that are helpful in accessing and altering respectively, internally stored data.
- Accessor Method: This method is used to access the state of the object i.e, the data hidden in the object can be accessed from this method. However, this method cannot change the state of the object, it can only access the data hidden. We can name these methods with the word get.
- Mutator Method: This method is used to mutate/modify the state of an object i.e, it alters the hidden value of the data variable. It can set the value of a variable instantly to a new value. This method is also called as update method. Moreover, we can name these methods with the word set.
Below examples illustrate the use of Accessor and Mutator methods in Python:
4 2 array('i', [5, 1, 3, 4, 2, 2, 7, 19])
So, here the index() and count() method only accesses the data so they are accessor methods but the append() method here modifies the array so its a mutator method.
So, here the name of the car was accessed using Accessor method i.e, get_make and then it was modified using Mutator method i.e, set_make.
- Private Methods in Python
- List methods in Python
- List Methods in Python | Set 1 (in, not in, len(), min(), max()...)
- Bound methods python
- Response Methods - Python requests
- Element methods in Selenium Python
- Web Driver Methods in Selenium Python
- Methods of Ordered Dictionary in Python
- Python | Float type and its methods
- Dunder or magic methods in Python
- Accessing Attributes and Methods in Python
- Dictionary Methods in Python | Set 1 (cmp(), len(), items()...)
- Http Request methods - Python requests
- Bound, unbound, and static methods in Python
- Python Input Methods for Competitive Programming
- Python | Implementing 3D Vectors using dunder methods
- Customize your Python class with Magic or Dunder methods
- Analysis of Different Methods to find Prime Number in Python
- Dictionary Methods in Python | Set 2 (update(), has_key(), fromkeys()...)
- 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.