Sobes.tech
Junior — Middle

What method is automatically invoked when an object of the class is instantiated?

sobes.tech AI

Answer from AI

In Python, when creating a new class object, the __init__ method is automatically called. This method serves as a constructor and is used to initialize the object's attributes.

Example:

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

p = Person("Ivan")  # When creating the object, __init__ will be called automatically
print(p.name)  # Will output: Ivan