1. Help Center
  2. Python Programming

What is init method in python?

The init method works similarly to the constructors in Java. The method is run as soon as an object is instantiated. It is useful for initializing any attributes or default behaviour of the object at the time of instantiation.
For example:
 
class InterviewbitEmployee:
 
# init method / constructor
def __init__(self, emp_name):
self.emp_name = emp_name
 
# introduce method
def introduce(self):
print('Hello, I am ', self.emp_name)
 
emp = InterviewbitEmployee('Mr Employee') # __init__ method is called here and initializes the object name with "Mr Employee"
emp.introduce()