KEMBAR78
Python-Inheritance.pptx
PYTHON-INHERITANCE
What is Inheritance
Inheritance is the ability to ‘inherit’ features or attributes from already
written classes into newer classes we make. These features and
attributes are defined data structures and the functions we can
perform with them, a.k.a. Methods. It promotes code reusability, which
is considered one of the best industrial coding practices as it makes the
codebase modular.
In python inheritance, new class/es inherits from older class/es. The
new class/es copies all the older class's functions and attributes
without rewriting the syntax in the new class/es. These new classes are
called derived classes, and old ones are called base classes.
Types of Inheritance in Python
1. Single Inheritance
2. Multiple Inheritance
3. Multi Level Inheritance
4. Hierarchical Inheritance in Python
5. Hybrid Inheritance in Python
Parent1 -> Child1 : Single Inheritance
Parent1 -> Child1 -> Child2 : Multi – Level Inheritance
Parent1 -> Child2 <- Parent2 : Multiple Inheritance
Single Inheritance in python
Single Inheritance is the simplest form of inheritance where a single
child class is derived from a single parent class. Due to its candid
nature, it is also known as Simple Inheritance.
Single Inheritance Example
Multiple Inheritance in Python
In multiple inheritance, a single child class is inherited from two or
more parent classes. It means the child class has access to all the
parent classes' methods and attributes.
Multiple Inheritance Example
Multilevel Inheritance in Python
In multilevel inheritance, we go beyond just a parent-child relation. We
introduce grandchildren, great-grandchildren, grandparents, etc. We
have seen only two levels of inheritance with a superior parent class/es
and a derived class/es, but here we can have multiple levels where the
parent class/es itself is derived from another class/es.
Example for MultiLevel Inheritance
Hierarchical Inheritance
Hierarchical Inheritance is the right opposite of multiple inheritance. It
means that, there are multiple derived child classes from a single
parent class.
Example for Hierarchical Inheritance
Hybrid Inheritance in Python
Hybrid Inheritance is the mixture of two or more different types of
inheritance. Here we can have many relationships between parent and
child classes with multiple levels.
Example for Hybrid Inheritance
Advantage of Inheritance in Python
Modular Codebase:
Increases modularity, i.e., breaking down codebase into modules, making it easier to understand.
Here, each class we define becomes a separate module that can be inherited separately by one
or many classes.
Code Reusability: the child class copies all the attributes and methods of the parent class into its class
and use. It saves time and coding effort by not rewriting them, thus following modularity paradigms.
Less Development and Maintenance Costs: changes need to be made in the base class; all
derived classes will automatically follow.
Disadvantage of Inheritance in Python
Decreases the Execution Speed: loading multiple classes because they
are interdependent
Tightly Coupled Classes: this means that even though parent classes
can be executed independently, child classes cannot be executed
without defining their parent classes.

Python-Inheritance.pptx

  • 1.
  • 2.
    What is Inheritance Inheritanceis the ability to ‘inherit’ features or attributes from already written classes into newer classes we make. These features and attributes are defined data structures and the functions we can perform with them, a.k.a. Methods. It promotes code reusability, which is considered one of the best industrial coding practices as it makes the codebase modular. In python inheritance, new class/es inherits from older class/es. The new class/es copies all the older class's functions and attributes without rewriting the syntax in the new class/es. These new classes are called derived classes, and old ones are called base classes.
  • 3.
    Types of Inheritancein Python 1. Single Inheritance 2. Multiple Inheritance 3. Multi Level Inheritance 4. Hierarchical Inheritance in Python 5. Hybrid Inheritance in Python Parent1 -> Child1 : Single Inheritance Parent1 -> Child1 -> Child2 : Multi – Level Inheritance Parent1 -> Child2 <- Parent2 : Multiple Inheritance
  • 4.
    Single Inheritance inpython Single Inheritance is the simplest form of inheritance where a single child class is derived from a single parent class. Due to its candid nature, it is also known as Simple Inheritance.
  • 5.
  • 6.
    Multiple Inheritance inPython In multiple inheritance, a single child class is inherited from two or more parent classes. It means the child class has access to all the parent classes' methods and attributes.
  • 7.
  • 8.
    Multilevel Inheritance inPython In multilevel inheritance, we go beyond just a parent-child relation. We introduce grandchildren, great-grandchildren, grandparents, etc. We have seen only two levels of inheritance with a superior parent class/es and a derived class/es, but here we can have multiple levels where the parent class/es itself is derived from another class/es.
  • 9.
  • 10.
    Hierarchical Inheritance Hierarchical Inheritanceis the right opposite of multiple inheritance. It means that, there are multiple derived child classes from a single parent class.
  • 11.
  • 12.
    Hybrid Inheritance inPython Hybrid Inheritance is the mixture of two or more different types of inheritance. Here we can have many relationships between parent and child classes with multiple levels.
  • 13.
    Example for HybridInheritance
  • 14.
    Advantage of Inheritancein Python Modular Codebase: Increases modularity, i.e., breaking down codebase into modules, making it easier to understand. Here, each class we define becomes a separate module that can be inherited separately by one or many classes. Code Reusability: the child class copies all the attributes and methods of the parent class into its class and use. It saves time and coding effort by not rewriting them, thus following modularity paradigms. Less Development and Maintenance Costs: changes need to be made in the base class; all derived classes will automatically follow.
  • 15.
    Disadvantage of Inheritancein Python Decreases the Execution Speed: loading multiple classes because they are interdependent Tightly Coupled Classes: this means that even though parent classes can be executed independently, child classes cannot be executed without defining their parent classes.