B.Tech Students: Apply for Live Programming Internship C, C++, Java, Python ,Web page Designing, PHP Python Multiple Inheritance | LiveCodeProgramming

Python Multiple Inheritance

Multiple Inheritance is a feature in Python where a class can inherit from more than one parent class. It helps in combining features of multiple classes into one.

Python में Multiple Inheritance का मतलब होता है कि एक class एक से ज्यादा classes से inherit कर सकती है। इससे हम अलग-अलग features को एक जगह जोड़ सकते हैं।

Example: Employee Inheriting from Person and Job
class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

class Job:
    def __init__(self, salary):
        self.salary = salary

class Employee(Person, Job):
    def __init__(self, name, age, salary):
        Person.__init__(self, name, age)
        Job.__init__(self, salary)

    def show_info(self):
        print(f"Name: {self.name}, Age: {self.age}, Salary: ₹{self.salary}")

e1 = Employee("Aryan", 26, 60000)
e1.show_info()

Output:

Name: Aryan, Age: 26, Salary: ₹60000
Why & When to Use Multiple Inheritance
  • To combine responsibilities from different classes (like Person + Job).
  • Helpful in large-scale systems like employee management, user-auth, etc.
  • Use carefully to avoid conflicts (e.g. same method name in both parent classes).
  • अलग-अलग classes के गुणों को एक class में लाने के लिए।
  • बड़े सिस्टम जैसे employee management में उपयोगी।
  • ध्यान से use करें अगर दोनों classes में एक ही नाम की methods हों।