📘 Lesson  ·  Lesson 87

Multiple Inheritance & MRO

Multiple Inheritance

💡 एक नज़र में

Java के उलट, Python एक class को कई parents से inherit करने देता है। MRO (Method Resolution Order) तय करता है कि कौन से parent का method पहले चले।

Example

Python
class A:
    def show(self): print("A")
class B(A):
    def show(self): print("B")
class C(A):
    def show(self): print("C")
class D(B, C):    # multiple inheritance
    pass

d = D()
d.show()          # MRO follow: D -> B -> C -> A
print(D.__mro__)
B (<class 'D'>, <class 'B'>, <class 'C'>, <class 'A'>, <class 'object'>)

सारांश

  • Python multiple inheritance देता है (D, B और C से)।
  • MRO method order तय करता है: ClassName.__mro__ से देखें।
← Back to Python Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 लाइव कोड एडिटर

इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.