+ 2
What is the meaning or use of self in python class for e.g. def hi(self)?
self argument use!!!!
2 odpowiedzi
+ 11
You use self when :
- Defining an instance method. It is passed automatically as the first parameter when you call a method on an instance, and it is the instance on which the method was called.
- Referencing a class or instance attribute from inside an instance method. Use it you want to call a method or access a name (variable) on the instance the method was called on, from inside that method.
+ 6
It is a reference to an instance of a class. You use it as the first argument in all methods and variables defined in a class to make a reference to a particular object of a class, not to the class itself.