Questions about Python __init__() and super()

Asked 2 years ago, Updated 2 years ago, 161 views

I'm studying super() What is the difference between ChildA() and ChildB() in the code below?

class Base(object):
    def __init__(self):
        print "Base created"

class ChildA(Base):
    def __init__(self):
        Base.__init__(self)

class ChildB(Base):
    def __init__(self):
        super(ChildB, self).__init__()

python inheritance super

2022-09-22 16:45

1 Answers

super() prevents explicit reference to the base class. It is valuable in multiple inheritance environments.

Check out standard docs


2022-09-22 16:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.