Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

How we can extend multiple Python classes in inheritance?



As per Python documentation ‘super’ can help in extending multiple python classes in inheritance.  It returns a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class. The search order is same as that used by  getattr() except that the type itself is skipped.

In other words, a call to super returns a fake object which delegates attribute lookups to classes above you in the inheritance chain. Points to note:

This does not work with old-style classes.You need to pass your own class and instance to super in Python 2.x. This requirement was waived in 3.x.

This will handle all multiple inheritance correctly. A method resolution order is generated and the lookups go through parent classes in this order.

Updated on: 2019-07-30T22:30:21+05:30

464 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements