Object Oriented Programming – Set 3:

We will learn about inheritance in this article which we have already discusssed in the previous blog of OOPs in Python for Data Science. Inheritance is very important in terms of its uses. As sometimes, we do not require to access all of the information in one go so we can inherit the properties as and when required.

One of the major advantages of OOP is re-use. In the case of Inheritance, a class is inherited by another class. The subclass then adds some of its attributes to the superclass.

oops python data science

Checking if a class is a subclass of another:

python data science

Object Class:

In Python object is root of all class.

When we use Python 3.x, “class Test(object)” and “class Test” are the same.

When we use Python 2.x “class Test(object)” makes the object as a parent and “class Test” creates old style class.

Multiple Inheritance and Python:

Python supports multiple inheritance. All parent classes are specified as comma separated list in bracket.

python data science oops

Accessing parent members in a subclass:

  1. Using Parent Class name:
  2. Using Super:

We will look at some of the examples to make things clear.

To learn more about inheretence in python for data science, 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.