![]() |
VOOZH | about |
__init__() method is a constructor which is automatically called when a new object of a class is created. Its main purpose is to initialize the object’s attributes and set up its initial state. When an object is created, memory is allocated for it and __init__ helps organize that memory by assigning values to attributes.
Let’s look at some examples.
You can pass parameters to initialize multiple attributes.
Max 30 Emilia 25
Explanation:
Like regular functions, __init__() can have parameters with default values.
Buddy Mixed 1 Max Golden Retriever 5
Explanation:
When using inheritance, both parent and child classes can have __init__() methods.
A init called B init called
Explanation: