+ 1

Is method is calling method or Is method is calling itself ? What does the statement in the description says ?

The first argument in a method is always the object that is calling the method

9th Jun 2021, 8:17 AM
lisa
4 Respostas
+ 3
example please. I dont really understand
9th Jun 2021, 8:33 AM
Oma Falk
Oma Falk - avatar
+ 1
I am taking about class. "The first argument in a method is always the object that is calling the method." What does this statement want to tell us ?
9th Jun 2021, 8:44 AM
lisa
+ 1
When writing a method for a class it is obligatory to make "self" the first argument of this method. "self" means that the method refers to the class and hence to the instantiated object.
9th Jun 2021, 9:38 AM
Lisa
Lisa - avatar
+ 1
a method call is of the form: instance.method() the 'method' function is bounded to a specific instance, wich is passed as first argument (usually called 'self') of the function... so, a method should ever have at least one argument in its declatation (signature) to receive it, even if you do not pass it explicitly... class Test: def __init__(self,arg): self.value = arg def method(self): print(self.value) t1 = Test(42) t2 = Test("forty-two") t1.method() # 42 t2.method() # forty-two
9th Jun 2021, 9:39 AM
visph
visph - avatar