In python's OOPs concept, a instance of class to be made to call other methods. I had a good explanation about self by arjun-sreedharan, how self works.
His explanation,
Let's say you have a class
ClassA
which contains a methodmethodA
defined as:
def methodA(self, arg1, arg2):
# do something
and ObjectA is an instance of this class.
Now when ObjectA.methodA(arg1, arg2)
is called, python internally converts it for you as:
ClassA.methodA(ObjectA, arg1, arg2)
The self
variable refers to the object itself.
But in my case, consider the same example given above. If methodA
is called without instance of class. How the internal convention of python is?
I mean, if methodA
is called like this --> ClassA().methodA(arg1, arg2)
. How would python assign the self
. Because in my case i have not declared any instance of class like this ObjectA = ClassA()
.