Extending to multiple inheritance
Python also supports multiple inheritance, where we can import a subclass from more than one base class or parent class. In such a scenario, the child class or the subclass inherits all the attributes and methods of the base classes. In this example, we will create two base classes, Product
and Branch
, and let the Sales
class inherit both these base classes. Here is a quick representation of the logic we’d be using:
Figure 2.8 – Multiple inheritance example
In the following code, we will be creating a Product
class where we will define the attributes for a product and a get_product
method to return the product details:
class Product:
_product_id = 100902
_product_name = 'Iphone X'
_product_category = 'Electronics'
...