Z
Z
zlodiak2019-01-29 21:47:36
Python
zlodiak, 2019-01-29 21:47:36

Where is the constructor inherited from?

Methods can be overloaded in python3. For example:

class A:
    def go(self):
        print('A!')

class B(A):
    def go(self):
        print('B!')

Here class B inherits from class A. But thanks to the overload in class B, the go() method has been replaced. This is understandable.
But it is not clear how the __init__() constructor can be overloaded in any class. As far as I understand this constructor is not inherited from anywhere. For example:
class C:
    __init__(self, name):
        self.name = name

This is the most common code, but class C does not have a parent, judging by the entry.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2019-01-29
@zlodiak

It has:

class C:
    def __init__(self, name):
        self.name = name

print(C.__mro__ )
print(isinstance(C('Вася'), object))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question