What is __init__ in python

__init__ in python is like constructor in other object oriented languages like PHP or Java, it automatically executed whenever an object or instance of that class is created.

See __init__ in python example

# class Employee definition
class Employee:
def __init__(self, fname, lname, age, department):
self.firstname = fname
self.lastname = lname
self.age = age
self.department= department

def attendance(employee_id, date):
self.attandante_date= date

# creating a new object or instance of Employee

stu1 = Employee(“Joji”, “John”, 32, “Marketing”)

My Thought

Your email address will not be published. Required fields are marked *