Bird
0
0

Which of the following is the correct syntax to define an __init__ method that takes a parameter name in a Python class?

easy📝 Syntax Q12 of 15
Python - Constructors and Object Initialization
Which of the following is the correct syntax to define an __init__ method that takes a parameter name in a Python class?
Adef __init__(self, name):
Bdef __init__(name):
Cdef init(self, name):
Ddef __init__(self):
Step-by-Step Solution
Solution:
  1. Step 1: Recall __init__ method signature

    The first parameter must be self to refer to the new object.
  2. Step 2: Check parameter list

    To accept a name argument, it must be added after self.
  3. Final Answer:

    def __init__(self, name): -> Option A
  4. Quick Check:

    First param is self, then others [OK]
Quick Trick: Always put self first in method parameters [OK]
Common Mistakes:
  • Omitting self parameter
  • Using init instead of __init__
  • Missing parameters after self

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes