What does self do? what is it meant to be? and is it mandatory? What does the __init__ method do? why is it necessary? etc | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What does self do? what is it meant to be? and is it mandatory? What does the __init__ method do? why is it necessary? etc

9th Jan 2017, 5:16 PM
chaurasiya abhimanyu harilal
2 Answers
+ 1
self is the same as 'this' keyword if you are familiar with java. it mean this object which we are in it. __init__ is to tell the python interpreter that this folder is a package and should treat accordingly
9th Jan 2017, 7:24 PM
Farzin Hooshmand
Farzin Hooshmand - avatar
+ 1
(facepalm) sorry, nope. self is indeed the current object, but you could name it this, s, t or anything you like. However, the __init__ method tells Python how to instantiate the object and initialize it.
9th Jan 2017, 7:56 PM
Amaras A
Amaras A - avatar