I
I
i_ikigai2020-05-28 00:23:16
Python
i_ikigai, 2020-05-28 00:23:16

I can’t understand the essence of the task with classes, am I generally doing the task correctly?

Create a class with two variables. Add a constructor with input parameters. Add a constructor that initializes the default members of the class. Add a destructor that displays a message about the deletion of the object.

class Class1:
    def __init__(self, a=5, b=4):
        self.a = a
        self.b = b
        print("Вызван метод __init__()")


    def __del__(self):
        print("Вызван метод __del__()")


c1 = Class1(1, 2)
c2 = Class1()
del c1
del c2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ayazer, 2020-05-28
@ayazer

In fact, everything is correct. Perhaps it is worth splitting the constructor into 2 different ones in order to eliminate the nitpick "in the task it is written to add the constructor 2 times, but you only have it 1"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question