__init__()
` function is a constructor method in Python classes. It is used to initialize the attributes of an object when it is created. __init__()
` function :class Person:
def __init__(self, name, age):
self.name = name
self.age = age
person1 = Person("Alice", 25)
person2 = Person("Bob", 30)
print(person1.name)
print(person1.age)
print(person2.name)
print(person2.age)
Alice
25
Bob
30
Person
` class with two attributes : `name` and `age`. The `__init__()
` function is called when we create a new object of the `Person
` class. self
` parameter refers to the object being created, and we use it to set the values of the `name
` and `age
` attributes. We create two objects of the `Person
` class (`person1
` and `person2
`) and print their `name
` and `age
` attributes.