Nearby lessons
86 of 108Python - self Variable
What Is self?
self is the reference to the current object inside a class.
It is used to access instance variables and instance methods.
Where Is It Used?
- Inside constructors
- Inside instance methods
Example
class Student:
def __init__(self, name):
self.name = nameImportant Note
self should always be the first parameter in instance methods and constructors.
Summary
| Term | Meaning |
|---|---|
| self | Current object |
| Instance variable | Variable tied to object |
| Instance method | Method that uses self |
🧠 Test Your Knowledge
3 QuestionsProgress: 0 / 3
Keep Going!Python - Instance Variables