Sep 17, 2019

Python Super method

class A:
  def __init__(self):
    print('A')

class AA(A):
  def __init__(self):
    print('AA')
    super().__init__() #No need to pass self, only args if required

a = A()
aa = AA()


class B:
  def __init__(self):
    print('B')

class BB(B):
  def __init__(self):
    print('BB')
    B.__init__(self) #need to pass self and args if required

b = B()
bb = BB()


Output:
A
AA
A
B
BB
B


No comments:

Post a Comment