0
What is self ?
7 odpowiedzi
+ 2
same as "this" in other languages
+ 2
Rishi Anand raises a good point. Since, in Python, you explicitly declare the 'self' parameter you could use any identifier, including 'this'. Using 'self' is just a convention that helps programmers understand each other's code. Of course you would need to know what 'this' means in the languages that use 'this' instead of 'self'.
+ 2
I understand... I just made an analogy. Here is the explanation.
You do make classes in python. And create objects as instance of those classes. self or this, is used to refer to that instantiated objected.
+ 1
'self' must be declared as the first parameter in class member functions. It is a reference to the instance of the class on which the member function was invoked (called). For example:
inst0 = clas();
inst0.func();
When 'func' needs to use a member 'mem' of 'inst' the expression 'self.mem' is used to refer to 'inst0.mem'. Elsewhere in the program:
inst1 = clas();
inst1.func();
Now when 'func' executes 'self.mem' will be referring to 'inst1.mem'.
+ 1
It's Rishi, Gordon...
0
I still don't understand but thanks for trying though
0
Sorry for the typo Rishi. Am am not great with a cellphone keyboard. Respects Gordon