Nearby lessons

86 of 108

Python - 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 = name

Important Note

self should always be the first parameter in instance methods and constructors.

Summary

Term Meaning
selfCurrent object
Instance variableVariable tied to object
Instance methodMethod that uses self

🧠 Test Your Knowledge

3 Questions

Progress: 0 / 3
Keep Going!Python - Instance Variables