Bird
0
0

Identify the mistake in this Python class:

medium📝 Debug Q6 of 15
Python - Object-Oriented Programming Foundations
Identify the mistake in this Python class:
class Vehicle:
    def __init__(self, type):
        type = type

v = Vehicle('Car')
print(v.type)
AThe __init__ method is missing
BThe instance variable is not assigned to self
CThe print statement syntax is incorrect
DThe class name should be lowercase
Step-by-Step Solution
Solution:
  1. Step 1: Review __init__ method

    The parameter 'type' is assigned to itself, not to self.type.
  2. Step 2: Understand instance variables

    To store data in an object, use self.type = type.
  3. Final Answer:

    The instance variable is not assigned to self -> Option B
  4. Quick Check:

    Instance variables need 'self.' prefix [OK]
Quick Trick: Always assign attributes with self.attribute = value [OK]
Common Mistakes:
  • Forgetting to use self for instance variables
  • Confusing parameter names with attributes
  • Assuming assignment without self works

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes