This article is in continuation with the previous blog of OOPs We will learn about data hiding and object printing in this article with respect to Python and its application in the field of Data Science. These concepts are very important as we have to deal with highly important data whose privacy cannot be compromised.
Double underscore is there before the attribute name, and such attributes will not be directly visible outside.
In the above example, as we tried to gain access to the hidden variable, it threw an exception.
In order to access the value of the hidden attribute, we should use the following syntax:
We should remember that nothing in Python is private; we only need to know the proper way to access.
It provides us information about the objects we are working with. We can perform this in Python by using _repr_ or _str_ methods.
Important Points related to printing:
- When no _str_ method is defined, print t uses _repr_
- In case no _repr_ method is defined then, default is run.