The __init__ method

The __init__() method must begin and end with two consecutive underscores. Here __init__ works as the class's constructor. When a user instantiates the class, it runs automatically. Let's see and understand this concept with the help of code. Here we will write the full code for classinit.py and then we will understand it line by line:

class Leapx_org():  def __init__(self,first,last,pay):    self.f_name = first    self.l_name = last    self.pay_amt = pay     self.full_name = first+" "+lastL_obj1 = Leapx_org('mohit', 'RAJ', 60000)L_obj2 = Leapx_org('Ravender', 'Dahiya',70000) print L_obj1.full_nameprint L_obj2.full_name

So, from preceding code, it seems difficult; let's understand it by line by line. The first line defines a class ...

Get Learn Python in 7 Days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.