Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 954703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:15:33+00:00 2026-05-16T00:15:33+00:00

How does super() work with multiple inheritance? For example, given: class First(object): def __init__(self):

  • 0

How does super() work with multiple inheritance? For example, given:

class First(object):
    def __init__(self):
        print "first"

class Second(object):
    def __init__(self):
        print "second"

class Third(First, Second):
    def __init__(self):
        super(Third, self).__init__()
        print "that's it"

Which parent method of Third does super().__init__ refer to? Can I choose which runs?

I know it has something to do with method resolution order (MRO).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:15:34+00:00Added an answer on May 16, 2026 at 12:15 am

    This is detailed with a reasonable amount of detail by Guido himself in his blog post Method Resolution Order (including two earlier attempts).

    In your example, Third() will call First.__init__. Python looks for each attribute in the class’s parents as they are listed left to right. In this case, we are looking for __init__. So, if you define

    class Third(First, Second):
        ...
    

    Python will start by looking at First, and, if First doesn’t have the attribute, then it will look at Second.

    This situation becomes more complex when inheritance starts crossing paths (for example if First inherited from Second). Read the link above for more details, but, in a nutshell, Python will try to maintain the order in which each class appears on the inheritance list, starting with the child class itself.

    So, for instance, if you had:

    class First(object):
        def __init__(self):
            print "first"
    
    class Second(First):
        def __init__(self):
            print "second"
    
    class Third(First):
        def __init__(self):
            print "third"
    
    class Fourth(Second, Third):
        def __init__(self):
            super(Fourth, self).__init__()
            print "that's it"
    

    the MRO would be [Fourth, Second, Third, First].

    By the way: if Python cannot find a coherent method resolution order, it’ll raise an exception, instead of falling back to behavior which might surprise the user.

    Example of an ambiguous MRO:

    class First(object):
        def __init__(self):
            print "first"
            
    class Second(First):
        def __init__(self):
            print "second"
    
    class Third(First, Second):
        def __init__(self):
            print "third"
    

    Should Third‘s MRO be [First, Second] or [Second, First]? There’s no obvious expectation, and Python will raise an error:

    TypeError: Error when calling the metaclass bases
        Cannot create a consistent method resolution order (MRO) for bases Second, First
    

    Why do the examples above lack super() calls? The point of the examples is to show how the MRO is constructed. They are not intended to print "first\nsecond\third" or whatever. You can – and should, of course, play around with the example, add super() calls, see what happens, and gain a deeper understanding of Python’s inheritance model. But my goal here is to keep it simple and show how the MRO is built. And it is built as I explained:

    >>> Fourth.__mro__
    (<class '__main__.Fourth'>,
     <class '__main__.Second'>, <class '__main__.Third'>,
     <class '__main__.First'>,
     <type 'object'>)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why doesn't this work ? class spin(threading.Thread): def __init__(self): super(spin,self).__init__() self._stop = False def
I have code like the following, class _Process(multiprocessing.Process): STOP = multiprocessing.Manager().Event() def __init__(self, queue,
Why does this work: self.array = newArray; But this doesn't: [[self mutableArray] addObject:object]; Meaning,
If subclass in objective-c wants to override a super class's method, does it have
does the find method work in jQuery with classes selectors ? For example: var
The problem is this: I have an abstract class that does some work in
Since java does not support multiple inheritance I have a problem getting this to
def pre_save(self, model_instance, add): value = super(MediaUploadField, self).pre_save(model_instance, add) if value and add: post_save.connect(self.someCallback,
I am trying to really understand how inheritance and the super keyword work. I
How does the Model work? I have a Registry Class like this: public class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.