The _init_ is a special type of method in Python that is called automatically when the memory is allocated for a new object. The main role of _init_ is to initialize the values of instance members for objects.
Example:
1
2
3
4
5
6
7
8
9
10
11
class Student:
def _init_ (self, name, age, marks):
self.name = name
self.age = age
self.marks = 950
S1 = Student("ABC", 22, 950)
# S1 is the instance of class Student.
# _init allocates memory for S1.
print(S1.name)
print(S1.age)
print(S1.marks)
Output:
1
2
3
ABC
22
950