+ 2

What is the meaning or use of self in python class for e.g. def hi(self)?

self argument use!!!!

28th Jul 2017, 6:39 AM
Vishal Agarwal
Vishal Agarwal - avatar
2 Answers
+ 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.
28th Jul 2017, 6:42 AM
Dev
Dev - avatar
+ 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.
28th Jul 2017, 6:43 AM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar