Bird
0
0

Which of these is a valid constructor definition with two parameters in Python?

easy📝 Conceptual Q2 of 15
Python - Constructors and Object Initialization
Which of these is a valid constructor definition with two parameters in Python?
Adef __init__(x, y):
Bdef __init__(self, x, y):
Cdef init(self, x, y):
Ddef __init__(self):
Step-by-Step Solution
Solution:
  1. Step 1: Check constructor syntax

    Constructor must be named __init__ and include self as first parameter.
  2. Step 2: Validate parameters

    Parameters after self are valid; so two parameters after self is correct.
  3. Final Answer:

    def __init__(self, x, y): -> Option B
  4. Quick Check:

    Constructor syntax = def __init__(self, ...) [OK]
Quick Trick: Constructor always needs self as first parameter [OK]
Common Mistakes:
  • Omitting self parameter
  • Using wrong method name (init instead of __init__)
  • Defining constructor without parameters when needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes