Bird
Raised Fist0

Which of the following correctly defines the magic method used to create a new instance of a class?

easy📝 Syntax Q3 of Q15
Python - Magic Methods and Operator Overloading
Which of the following correctly defines the magic method used to create a new instance of a class?
Adef __new__(cls, *args, **kwargs):
Bdef __init__(self, *args):
Cdef __create__(self):
Ddef __start__(cls):
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of __new__

    __new__ is the magic method responsible for creating and returning a new instance of a class.
  2. Step 2: Compare with __init__

    __init__ initializes an already created instance, but __new__ actually creates it.
  3. Final Answer:

    def __new__(cls, *args, **kwargs): -> Option A
  4. Quick Check:

    __new__ creates instances [OK]
Quick Trick: __new__ creates, __init__ initializes [OK]
Common Mistakes:
MISTAKES
  • Confusing __init__ with __new__
  • Using non-standard method names like __create__
  • Assuming __start__ is a magic method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes