U
U
UNy2018-02-21 16:50:42
Python
UNy, 2018-02-21 16:50:42

Inheritance, __init__ method?

there is a class Person and there is a child class Manager.

class Person:
    def __init__(self, name, job, salary):
        self.name = name
        self.job = job
        self.salary = salary

class Manager(Person):
    def __init__(self, name, salary):
        super().__init__(name, "manager", salary)

In order not to prescribe a name when creating an instance, I set it immediately in the class itself.
Question: what is the difference super().__init__(name, "manager", salary)from Person.__init__(name, "manager", pay)?
2 method is used if the class has many descendants?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-02-21
@UNy

The shape Person.__init__(name, "manager", pay)is a legacy of Python 2.5 and is deprecated and deprecated.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question