0

FIRST ONE

class Animal():
    def __init(self, name):
        self.name = name
    def talk(self):
        pass

THE OTHER ONE:

class Rectangle():
    def __init__(self, length, breadth):
        self.length = length
        self.breadth = breadth

    def getArea(self):
        print(self.length*self.breadth, "is area of Rectangle")
Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
Dragan021
  • 1
  • 1
  • Does this answer your question? [Why do some functions have underscores "\_\_" before and after the function name?](https://stackoverflow.com/questions/8689964/why-do-some-functions-have-underscores-before-and-after-the-function-name) – ChristianB Jan 02 '21 at 18:47

2 Answers2

0

As far as the first one is concerned I am not sure if I have seen it anywhere but for the second one the __init__ is a reserved method in python classes. It is called a constructor in object-oriented terminology. This method is called when an object is created from a class and it allows the class to initialize the attributes of the class. For more info check this link

Hadi Mir
  • 4,497
  • 2
  • 29
  • 31
0

It seems I got confused, I am having python course and it seems this is only name of a definition in class and init is understandable..

Thank you for your time, I do appreciate the answer! It was my bad that cost me 30min or searching something that doesn't exist...... My bad...

Dragan021
  • 1
  • 1