What is the magic method for creating an instance | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

What is the magic method for creating an instance

python

11th Jul 2018, 1:33 AM
Oscar Obasi
Oscar Obasi - avatar
4 Answers
+ 8
__new__ handles object creation and __init__ handles object initialization
11th Jul 2018, 4:15 AM
Mert Yazıcı
Mert Yazıcı - avatar
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
19th Mar 2019, 9:10 PM
Romel Gomez
Romel Gomez - avatar
- 2
Which language is best
7th Dec 2019, 7:08 PM
VISHWAS
- 2
__init__
7th Jan 2022, 7:20 PM
Isesele Victor
Isesele Victor - avatar