__init__ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

__init__

im not so sure whats __init__ or __str__ at all can some one please explain it to me please

20th Jan 2019, 7:45 PM
Shmuel israel Zilberman
Shmuel israel Zilberman - avatar
1 Answer
0
Functions starting and ending with double underscores __ are called special methods or dunder methods. You can use it to override behaviors of built-in types in your class. __init__ dunder is a constructer which takes care of setting up the object. Whenever an object of a class is instantiated, this method is called. __str__ is used to represent objects. Whenever you use print function, this method is called.
20th Jan 2019, 8:13 PM
Шащи Ранжан
Шащи Ранжан - avatar