Bird
Raised Fist0

Find the error in this class definition:

medium📝 Debug Q6 of Q15
Python - Classes and Object Lifecycle
Find the error in this class definition:
class Car:
    def __init__(self, model):
        model = model

c = Car('Tesla')
Amodel is not assigned to self.model
BSyntax error: missing colon
CClass name should be lowercase
DMissing self parameter in __init__
Step-by-Step Solution
Solution:
  1. Step 1: Check constructor parameters

    self is present, so no error there.
  2. Step 2: Check attribute assignment

    Inside __init__, model = model assigns parameter to itself, not to the object. It should be self.model = model.
  3. Final Answer:

    model is not assigned to self.model -> Option A
  4. Quick Check:

    Assign attributes with self.attribute = value [OK]
Quick Trick: Always assign to self.attribute inside __init__ [OK]
Common Mistakes:
MISTAKES
  • Assigning parameter to itself instead of self attribute
  • Omitting self parameter
  • Wrong class naming conventions (not error)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes