Python super().__init__() doesn't call multiple inherited classes?

19 views Asked by At

In my example i have two classes FirstClass SecondClass

class FirstClass():
    
    def __init__(self) -> None:
        print("First class instance creation")
        pass
    
class SecondClass():
    
    def __init__(self) -> None:
        print("Second class instance creation")
        pass
    

After inherting them in SampleClass like this

class SampleClass(FirstClass, SecondClass):
    
    def __init__(self) -> None:
        super().__init__()
        super(SecondClass, self).__init__()

but its not calling the SecondClass,

FirstClass.__init__(self=self)
SecondClass.__init__(self=self)

but this method works,

MY QUESTIONS IS: Why its working like this ?, How super() function will work in multiple inheritances?

I'm trying to trigger both inherited classes using super() method

This is what I'm getting while using super() method

First class instance creation

but it is not working as i expected,

this is what i expecting

First class instance creation
Second class instance creation

Second class instance creation

0

There are 0 answers