In Python,__init__ is a method or constructor. It is automatically called to allocate memory when a new object or instance of a class is created. All classes have the __init__ method.
Here’s how to use the __init__ method in Python:
# class definition
class Student:
def __init__(self, fname, lname, age, section):
self.firstname = fname
self.lastname = lname
self.age = age
self.section = section
# creating a new object
stu1 = Student(“Sara”, “Ansh”, 22, “A2”)