0

Is there a (meaningful) difference the two classes below?

class A(Foo, Bar):
    ...

vs

class B(Bar, Foo):
    ...
theEpsilon
  • 1,561
  • 16
  • 25
  • short answer: yes. Google "Python MRO" for details. (But it won't if `Foo` and `Bar` have no method names in common, and don't have any common base classes.) – Robin Zigmond Sep 22 '20 at 21:52

1 Answers1

1

Does order of class bases in python matter?

Yes, it does. Consider the following:

class A:
    def foo(self):
        print('class A')
class B:
    def foo(self):
        print('class B')
class C(A, B):
    pass

c = C()
c.foo() # class A

Methods are resolved from left-to-right—e.g., in the example, the foo method comes from class A because A comes before B.