Bird
Raised Fist0

What is the purpose of the __init__ method inside a Python class?

easy🧠 Conceptual Q2 of Q15
Python - Classes and Object Lifecycle
What is the purpose of the __init__ method inside a Python class?
ATo define a class variable
BTo initialize a new object when created
CTo delete an object
DTo print the class name
Step-by-Step Solution
Solution:
  1. Step 1: Understand __init__ role

    The __init__ method is a special method called automatically when a new object is created.
  2. Step 2: Identify its purpose

    It sets up initial values or state for the new object, so it initializes the object.
  3. Final Answer:

    To initialize a new object when created -> Option B
  4. Quick Check:

    __init__ method = initialize object [OK]
Quick Trick: Remember __init__ runs when object is created [OK]
Common Mistakes:
MISTAKES
  • Thinking __init__ deletes objects
  • Confusing __init__ with class variables
  • Assuming __init__ prints output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes