Python: self and the implicit argument

Self-tutoring about Python: the tutor mentions the self concept.

To Python, when you call an ordinary class method (as opposed to a static one), the object whose method is being called is an implicit parameter. You can call it externally without mentioning that. Internally, however, it needs to be there.

class Class0:
def hello(self): #self means this object
print(“hello from Class0”)

When you make an object of Class0, like so:
you can then call its “hello” method without giving any parameters:

Within the class definition, people typically use self as the parameter that represents the object. Yet, self is not a keyword; duck would work equally well, so far as I know.


Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Leave a Reply