Self
There is only one special difference between the methods of classes in Python and normal functions-they must have an extra first parameter name, but you do not assign a value to this parameter when calling this method, and Python provides this value. This particular variable refers to the object itself, according to the Convention its name is self . Although you can give this parameter any name, it is best to use self this name-other names are deprecated.
If there is a class called fruit and an instance of this class, Apple. When you call this instance of Apple .method(arg1, arg2) , this will be automatically converted from Python to fruit .method(apple, arg1, arg2) -that's how it self works. This also means that if you have a method that does not require parameters, you need to define a parameter for the method self .
Search
Copy
Self in Python (Python note)