Python Tutorial
About Lesson

In this Python lesson we want to learn about Python Class Inheritance, also we are going to create a practical example in Python Class Inheritance.

 

 

What is Class Inheritance in Python ?

Class inheritance is one of the most important concepts in object oriented programming, basically a class inheritance allows us to create a relationship between two or more classes. now in object oriented programming one class can inherit attributes and methods from another class.

 

In this image you can see that we have two classes, the first one is our Class A and we have some variables with one method in this class, in term of class inheritance we can call this class a Base Class, Parent Class or Super class. we have another Class B, now this class extends or inherit from Class A, and for this class we can call Derived Class, Child Class or Sub Class. as we have already said when a class extends from the the base class, the derived class can access to all attributes and methods of the base class. for example in here our Class B child class can access to the fname and lname attributes of the Class A super class.

Python Class Inheritance
Python Class Inheritance

 

 

Now let’s create a practical example on class inheritance in python.

 

So in the above code we have a base class and we have a derived class, in the base class we have some instance attributes and a method for printing the variables. now our derived class can access to all attributes and method of the base class, for example Student class can access to the name, email variables and also full_info() method.

 

 

If you run the code this will be the result.

Python super Class
Python super Class

 

 

Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.
Exercise Files
No Attachment Found
No Attachment Found