Python ClassesLesson 40Free preview
Python self Parameter
This lesson is part of Python · All levels
Summary
The self parameter represents the object instance that is working so that the method can access its own attribute. Self is always written as the first parameter when defining the method, but it is not necessary to write it when calling the method from the object. Python automatically transfers the calling object to the self position.
Key points
- Self is a naming convention; it can be replaced, but it is highly recommended to keep writing self.
- When defining the method self must exist, when calling object.method() self is not written.
- Through self.attribute, the method reads and changes the object's data.
- Self can also be used to return the object itself from a method.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.