Python
Python
of a class is created. It is called the constructor because it is used to initialize (set up) the
object with some values.
Simple Explanation:
Example:
class Person:
def show_info(self):
p1 = Person("Chhavi", 22)
1. Automatic Initialization:
o Example: If you create multiple Person objects, each can have a different
name and age.
3. Improves Code Readability & Organization:
o Makes code cleaner by ensuring every object starts with valid data.