From what I understand about self, it refers to the current instance of the class.
Isn’t this the default behaviour at all times anyways? For example, isn’t
self.var_one = method(args)
equivalent to
var_one = method(args)
If so, what is the use of self?
In most cases
self.foois indeed redundant because you can just writefoofor the same effect, but in this case it is not and theselfis required.var_one = method(args)will create a local variable calledvar_one, it will not call any method or do anything else toself.self.var_one = method(args)will call the methodvar_one=onselfwith the argumentmethod(args).Another case where the use of
selfis non-optional would be if you want to pass it as an argument to a method, i.e.some_method(self)– you can’t do that without theselfkeyword.