The init method is a special method in Python classes that is automatically called when an object of that class is created. It is used to initialize the attributes of the object.

Example:

class Person:
def __init__(self, name, age):
self.name = name
self.age = age

p1 = Person(“John”, 20)

print(p1.name)
print(p1.age)

# Output
John
20

Leave a Reply

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