Bird
0
0

Find the error in this code:

medium📝 Debug Q6 of 15
Python - Object-Oriented Programming Foundations
Find the error in this code:
class Book:
    def __init__(title):
        self.title = title

b = Book('Python 101')
AMissing self parameter in __init__ method
BIncorrect class name
CMissing parentheses when creating object
DUsing wrong attribute name
Step-by-Step Solution
Solution:
  1. Step 1: Check method parameters

    The __init__ method must have self as its first parameter to refer to the object being created.
  2. Step 2: Identify the missing self

    Here, __init__ only has title parameter, so self is missing, causing an error.
  3. Final Answer:

    Missing self parameter in __init__ method -> Option A
  4. Quick Check:

    __init__ must include self first [OK]
Quick Trick: __init__ always needs self as first parameter [OK]
Common Mistakes:
  • Omitting self in __init__
  • Confusing self with other parameter names
  • Not passing arguments correctly when creating object

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes