Bird
0
0

What is wrong with this __init__ method?

medium📝 Debug Q7 of 15
Python - Constructors and Object Initialization

What is wrong with this __init__ method?

class Book:
    def __init__(title, author):
        self.title = title
        self.author = author
AThe method name should be <code>init__</code>.
BThe <code>self</code> parameter is missing as the first argument.
CThe attributes should not use <code>self</code>.
DThe class name should be lowercase.
Step-by-Step Solution
Solution:
  1. Step 1: Check method parameters

    The first parameter of __init__ must be self to refer to the instance.
  2. Step 2: Identify error

    Here, self is missing, so title is treated as self, causing errors.
  3. Final Answer:

    The self parameter is missing as the first argument. -> Option B
  4. Quick Check:

    __init__ always needs self first [OK]
Quick Trick: self must be first parameter in __init__ [OK]
Common Mistakes:
  • Omitting self
  • Misnaming __init__
  • Ignoring case conventions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes