Recall & Review
beginner
What is the purpose of the
__init__ method in a Python class?The
__init__ method is called automatically when a new object is created. It initializes the object's attributes with values.Click to reveal answer
beginner
What happens if you don't define an
__init__ method in your Python class?Python uses a default constructor that does nothing, so the object is created but no attributes are initialized automatically.
Click to reveal answer
beginner
How can you pass values to initialize an object in Python?
You pass values as arguments when creating the object, and the
__init__ method receives them to set the object's attributes.Click to reveal answer
intermediate
What is the order of execution when creating an object in Python?
First, memory is allocated for the new object. Then, the
__new__ method runs (usually default). Next, __init__ runs to initialize the object.Click to reveal answer
intermediate
Can the
__init__ method return a value?No,
__init__ must return None. It only initializes the object and does not create or return it.Click to reveal answer
What is the role of the
__init__ method in Python?✗ Incorrect
The
__init__ method sets up the object's initial state by initializing its attributes.What happens if you create an object without defining
__init__?✗ Incorrect
Without
__init__, Python creates the object but does not set any attributes automatically.Which method is called first when creating a new object?
✗ Incorrect
__new__ creates the object in memory before __init__ initializes it.Can
__init__ return a value other than None?✗ Incorrect
__init__ must always return None; returning anything else causes an error.How do you pass values to initialize an object?
✗ Incorrect
Arguments passed when creating the object are received by
__init__ to set attributes.Explain the flow of object initialization in Python from creation to attribute setup.
Think about what happens first and what sets the object's data.
You got /4 concepts.
Describe how you can customize object creation using
__init__ and what happens if it is missing.Focus on how objects get their starting values.
You got /3 concepts.