Bird
Raised Fist0

Which of the following is the correct way to define a constructor method in a Python class named Book?

easy🧠 Conceptual Q3 of Q15
LLD - Design — Library Management System
Which of the following is the correct way to define a constructor method in a Python class named Book?
Adef constructor(self, title, author):
Bdef __init__(self, title, author):
Cdef Book(self, title, author):
Ddef init(self, title, author):
Step-by-Step Solution
Solution:
  1. Step 1: Recall Python constructor syntax

    Python uses the special method __init__ to initialize new objects.
  2. Step 2: Match correct method signature

    The correct constructor is defined as def __init__(self, ...), so def __init__(self, title, author): matches this syntax.
  3. Final Answer:

    def __init__(self, title, author): -> Option B
  4. Quick Check:

    Python constructor = __init__ method [OK]
Quick Trick: Python constructors use __init__ method [OK]
Common Mistakes:
MISTAKES
  • Using constructor instead of __init__
  • Naming method same as class
  • Missing double underscores in __init__

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes