self in python class

In Previous Chapter we found "self" inside class. We will describe here, what it is. Let's understand "class" , "self" in python more from below list gathered from various sources.

  1. "self" is the instance object automatically passed to the class instance's method when called  ,  to identify the instance that called it. 
  2. "self" does not need to be used when calling a method when you already have an available instance.
  3. The reason "self" is there (by convention) is that when the Python runtime sees a call of the form Object.Method(Param1,Param2), it calls Method with parameters (Object,Param1,Param2). That is why, first parameter is "self".
  4. object is the first argument to the function, which traditionally is named self in the parameter list. (You can, in fact, name it something else, and your code will work correctly, but other Python coders will frown at you.)
  5. Classes are more than that in Python. Classes are objects too.
  6. As soon as you use the keyword class, Python executes it and creates an OBJECT.
  7. self is not a reserved keyword in python it’s just a strong convention. Many people say that why do we have to write self ? Why can’t we have it set automatically like in Java ? Someone also filed a PEP (improvement suggestion) in which he suggested to remove the explicit assignment of self keyword. However Guido Van Rossum (the maker of python) wrote a blogpost in which he told why explicit self has to stay

Loading ...

Related Results :

  1. self in python class
  2. Built-In & More Classes & Objects
Note :
  • Related Posts are generally User Blog posts.
  • or Other tutorials from other networks of
  • Any registered user can create related posts based on search term tags.

About the Author