Understanding self keyword and __init__ function

In the book learn Python the hard way, Zed mentioned : “In the MyStuff function init then gets
this extra variable self, which is that empty object Python made for me, and I can set variable in on it just
like you would with module, dict and other object”

My question is:
So self in Python is kind of like this keyword in Java, and
__init__function in Pythin is kind of like constructor in Java?

Your analogy with Java is correct. Some might says that is not 100% identical but for practical purposes it works as you describe it.

1 Like