 Hello, everyone. Welcome to Python tutorials. Myself, Samprit Patel, assistant professor, Department of Computer Science and Engineering, Balchan Institute of Technology, Sholapur. Today, we are going to learn about inheritance in Python. At the end of this video, you'll be able to write a Python script in object oriented programming style. So before starting with hands on, let's just see what is inheritance in Python. Inheritance is a capability of one class to derive or inherit the properties from another class. Some of this, the benefits of inheritance are it represents a real world relationship level. Second, it provides reusability of code. We don't have to write the same code again and again. It allows us to add more features to the class without modifying. It is a trance. It is transitive in nature, which means that if we have a class B that in that is inherited from another class A, then all the subclasses of B would automatically inherit from a class A. So there are different types of inheritance that in the way it can be implemented. Single inheritance, multiple inheritance, multi level inheritance, hierarchical inheritance and hybrid inheritance. In this video, we will cover the first three that is single inheritance, multi multiple inheritance and multi level inheritance. So let's move on to hands on session. So how to implement a single inheritance or what is single inheritance? Single inheritance enables a derived class to inherit properties from a single parent class, thus enabling code reusability and addition of new features to the existing code. So let's create a single inheritance. So first we'll create a base class or what we call also call as a parent class. So class parent. And here we'll have a function, say function one, which will help us to print, which will print this function is of parent. Now, how to create inheritance? So we have to create a derived class, derived class. So here we want to inherit class parent. Okay, so class child and in the bracket, you'll place the name of the class which you want to inherit that is parent. Okay, so this will inherit parent class to the child class. So here we'll create another function, say function two, which will print, which will print this function class. Okay, now we need to create an object to access the classes. So see, we'll create an object say obj is equals to child. Okay, we have created an object of a child class. Now, with this object, as child class inherits parent class, we can access this function using the object of the child class. So obj.function1 and using the same object obj.function2. Okay, let's run the code. So yes, the first is the function is of parent class and second is the function is of child class. Okay, so see, we have just created an object of a child class using which you can you are also accessing the function of a parent class as we are inherited a parent class to a child class. Okay, so hope you are clear with first type of inheritance that is single inheritance. Now, multiple inheritance when a class can be derived from more than one base classes, this type of inheritance is called multiple inheritance in multiple inheritance, all the features of the base classes are inherited into the derived class. Okay, so let's see an example of multiple inheritance. So here we'll have two classes as a base class. So let's say class mother and we'll have a function. So mother name will have is equals to a string value will print the name of mother. So we'll have function mother function mother and it will print it will print self.mother name. Now we'll have another class father. This will have father's name as a string value. It will have a function father, which will print the name of the father that is print self dot father's name. Now see these both classes are base classes. Now we have now we'll have to create a derived class say class child and it will derive from class mother. So if you want to inherit two classes, you just have to specify the name of both the classes separated by comma. Okay, so class child inherits mothers and father. So here we'll have a function saying parents. This will print access the and print name of father name of father will be self dot father name. And it will also print mother's name using self dot mother name. Okay, now we'll create an object to access this functions. So s one is equals to child class. Okay, we have created an object. So s one dot we have to specify father's name, say a b c and s one dot mother's name is equals to D e f. Okay, now we'll print the names s one dot parents s one dot parents. Okay, so let's run. So see father is a b c and mother is D e f. Okay, I hope you're not clear with this. Now let's move on to the third type that is multi level inheritance. Okay, so in multi level inheritance features of the base class and the derived class are further inherited into a new derived class. Okay, so let's see an example for this. So we'll have class before going to this example, just try to answer this question, which of the following best describes inheritance ability of class to derive members from another class as a part of its own definition means of bundling instance variables and methods in order to restrict access to certain class members focuses on variables and passing the variables to a function allows implementation of elegant softwares that is well designed and easily modified. So yes, the answer is a that is ability of class to derive members of another class as a part of its own definition. Now moving on to multi level inheritance, the feature of base class and derived class are further inherited into a new derived class. So this is similar to the relationship between child and a grandfather. So let's see class grandfather. Okay, we have a class grandfather, this is the base class, which has grandfather name, and it will print. So it will have a function grandfather. Okay, and it will print self dot self dot grandfather name. Similarly, we'll have a class will have a class father will have a class father. So I'll just copy and paste this. So here we'll have father's name. We'll have function father. And it will return father's name. So this particular class inherits grandfather inherits grandfather. Now we'll have a third class, we'll have a third class sick class child, okay, or son, which will inherit father. Okay, I'll just change this to capital F. Okay, and this son will print create a function parent. And it will print grandfather's name using self dot grandfather name and it will print father name and access it using self dot father name. Now we'll create object son. So I'll just I'll just take this and paste it. Okay, so here it will have grandfather name. And your father's name. Okay, and the class is son. Okay, so let's execute. So yes, grandfather's name is ABC and father's name is df. Hope you have understood I've used these references to create this video programming Python three and core Python programming. Thank you.