+ 6
What is the magic method for creating an instance
4 odpowiedzi
+ 8
__new__ handles object creation and __init__ handles object initialization
0
Well, the answer of @Mert Yazici, has most sense to me:
__new__ is the first step of instance creation. It's called first, and is responsible for returning a new instance of your class. In contrast, __init__ doesn't return anything; it's only responsible for initializing the instance after it's been created.
ref: https://stackoverflow.com/a/674369/2513972
The question of the Python tutorial, mark correct: __init__ and should be __new__ for, What is the magic method for creating an instance?
That question is incorrect. Find it at:
Object-Oriented Programming
Magic Methods & Operator Overloading
- 2
Which language is best
- 2
__init__