Bird
0
0

Identify the error in this class definition:

medium📝 Debug Q14 of 15
Python - Constructors and Object Initialization
Identify the error in this class definition:
class Car:
    def __init__(color):
        self.color = color

my_car = Car("red")
AMissing quotes around "red"
BMissing self parameter in __init__ method
CCannot assign to self.color
DWrong method name, should be __start__
Step-by-Step Solution
Solution:
  1. Step 1: Check __init__ method parameters

    The first parameter of __init__ must be self to refer to the instance. Here, self is missing.
  2. Step 2: Confirm other parts are correct

    Method name __init__ is correct, assignment to self.color is valid, and "red" is properly quoted.
  3. Final Answer:

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

    __init__ first parameter = self [OK]
Quick Trick: Always include self as first parameter in __init__ [OK]
Common Mistakes:
  • Forgetting self parameter
  • Changing __init__ method name
  • Misunderstanding self usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes