Inheritance in Python
Understanding Object-Oriented
Programming Concepts
What is Inheritance?
• • Inheritance allows a class to inherit
attributes and methods from another class.
• • The class that inherits is called the Child
(Derived) class.
• • The class from which it inherits is called the
Parent (Base) class.
Syntax of Inheritance
• class Parent:
• # parent class members
• class Child(Parent):
• # child class members
Simple Example
• class Animal:
• def speak(self):
• print('Animal speaks')
• class Dog(Animal):
• def bark(self):
• print('Dog barks')
Types of Inheritance
• • Single Inheritance
• • Multiple Inheritance
• • Multilevel Inheritance
• • Hierarchical Inheritance
• • Hybrid Inheritance
Multilevel Inheritance Example
• class A:
• pass
• class B(A):
• pass
• class C(B):
• pass
Benefits of Inheritance
• • Code reusability
• • Cleaner and more maintainable code
• • Supports hierarchical classification
Conclusion
• Inheritance helps in reusing code and creating
structured programs.
• It is a core feature of Object-Oriented
Programming in Python.