Parent Class method working on subclass object

  python, python-2.7, python-3.x
class intset(object):
    def __init__(self, x):
        self.vals = [x]

    def insert(self, e):
        if not e in self.vals:
            self.vals.append(e)

    def member(self, e):
        return e in self.vals


class add(intset):
    def __init__(self, x, y):
      intset.__init__(self, x)
      self.vals.append(y)

    def __str__(self):
      self.vals.sort()
      return '[' + ','.join([str(e) for e in self.vals]) + ']'


a=intset(0)
a.insert(1)
a.insert(2)
a.insert(3)

For the above code can someone please explain that why calling the member method using the parent class is returning True?

intset.member(a,3)

add.member(a,3)

Although a is an instance of the add class. But the above call using the parent class (intset) is returning the same result as calling the member method using subclass (add)

Source: Python-3x Questions

LEAVE A COMMENT