Object-Oriented Programming – Set 2:

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.

Data Hiding:

Double underscore is there before the attribute name, and such attributes will not be directly visible outside.

python for data science

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.

Printing Objects:

It provides us information about the objects we are working with. We can perform this in Python by using _repr_ or _str_ methods.

python data science

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.

To learn more about OOPs and its uses in Python programming for Data Science, then you can check this and this as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.