Encapsulation in Python:
|We can use the PyCharm code editor for this example. If you do not know about it then follow this link- How to install PyCharm for Python and create a program in it.|
(1) Encapsulation refers to hiding the internal class data. As a rule of thumb, in object-oriented programming, class data should not be directly accessible outside the class.
(2) Getters- These are methods used to access the private attributes from a class or its instance. Setters- These are methods used to set the private attributes of a class or its instance. Getters and Setters methods can also be used to implement additional logic for accessing or setting the attributes, and it is convenient to maintain such additional logic in one place.