Previous

self variable

Next
  1. Within a Python class, to refer to the current object, a variable named self is used.
  2. self is a reference variable that always points to the current object.
  3. The first argument to the constructor and instance methods is always self.
  4. 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.
  5. The main purpose of the self variable within the class is to declare instance variables and to access their values.
  6. self is not a keyword; you can use any name (like delf or kelf), but it is recommended to use self.
  7. You cannot use self from outside of the class.