হ্যাঁ, পাইথন মাল্টিপল ইনহেরিটেন্স সমর্থন করে।
C++-এর মতো পাইথনে একটি ক্লাস একাধিক বেস ক্লাস থেকে ডেরাইভ করা যায়। এটাকে মাল্টিপল ইনহেরিটেন্স বলা হয়।
মাল্টিপল ইনহেরিটেন্সে সব বেস ক্লাসের বৈশিষ্ট্য ডেরাইভড ক্লাসে ইনহেরিট হয়।
উদাহরণ
class Animal:
def eat(self):
print("It eats insects.")
def sleep(self):
print("It sleeps in the night.")
class Bird(Animal):
def fly(self):
print("It flies in the sky.")
def sing(self):
print("It sings a song.")
print(issubclass(Bird, Animal))
Koyal = Bird()
print(isinstance(Koyal, Bird))
Koyal.eat()
Koyal.sleep()
Koyal.fly()
Koyal.sing()
উপরের উদাহরণে Bird ক্লাস Animal ক্লাস থেকে ইনহেরিট করেছে।
- Animal হল প্যারেন্ট ক্লাস, যাকে সুপার ক্লাস বা বেস ক্লাসও বলা হয়।
- Bird হল চাইল্ড ক্লাস, যাকে সাবক্লাস বা ডেরাইভড ক্লাসও বলা হয়।
issubclass মেথড নিশ্চিত করে যে Bird Animal ক্লাসের সাবক্লাস।
আউটপুট
True True It eats insects. It sleeps in the night. It flies in the sky. It sings a song.