Previous
self variable
Next
- Within a Python class, to refer to the current object, a variable named
self is used.
self is a reference variable that always points to the current object.
- The first argument to the constructor and instance methods is always
self.
- When calling the constructor or instance methods, you are not required to pass any value to the
self variable. The Python Virtual Machine (PVM) automatically provides this value.
- The main purpose of the
self variable within the class is to declare instance variables and to access their values.
self is not a keyword; you can use any name (like delf or kelf), but it is recommended to use self.
- You cannot use
self from outside of the class.