2

I'm trying to understand the behavior of following Python code.

class A(object):
    def print_x(self):
        print "In A: X"

class B(A):
    def print_x(self):
        super(B, self).print_x()
        print "In B: X"

class C(A):
    def print_x(self):
        super(C, self).print_x();
        print "In C: x"

class D(B, C):   # <----------- #1 
    def print_x(self):
        super(D, self).print_x()
        print "In D: x"

d = D();
d.print_x();

If I run above program I get an output like below:

In A: X
In C: x
In B: X
In D: x

If I change the statement #1 in the code to class D(C, B) I get following output

In A: X
In B: X
In C: x
In D: x

Can anybody explain the internal working behind this code.

Ganesh Satpute
  • 3,664
  • 6
  • 41
  • 78

0 Answers0