Last modified: Nov 27, 2026

What Is Self in Python? Explained

Self is one of the first things new Python learners see. It appears in almost every class method. Many beginners wonder what it means and why it is there.

In short, self refers to the current instance of a class. It lets an object access its own attributes and methods.

This guide explains self in plain language. You will see how it works, why it matters, and how to use it correctly with clear code examples.

What Does Self Mean in Python?

Self is a reference to the object that is calling a method. When you create an object from a class, that object becomes the value of self inside its methods.

Think of a class as a blueprint. Each object built from that blueprint is a separate thing. Self tells the method which object it is working with.

Self is not a reserved keyword in Python. It is a strong convention. Almost every Python developer uses the name self. You should follow this convention too.

When you call a method, Python passes the object automatically as the first argument. You do not pass it yourself. This is why the first parameter of an instance method is always self.

Why Is Self Needed?

Python needs a way to link methods to specific objects. Without self, a method would not know which object's data to read or change.

Imagine a class with many objects. Each object may hold different values. Self makes sure a method touches only the data of the object that called it.

Self also lets methods call other methods on the same object. This keeps code organized and reusable.

If you want to see the mechanics in more detail, this guide on the Python self parameter example walks through the parameter step by step.

Self and the __init__ Method

The __init__ method is a special method. It runs when you create a new object. It is often called the constructor.

Inside __init__, self refers to the object being created. You use self to store values on that object.

These stored values are called attributes. Attributes belong to each object separately.

Here is a simple example:


class Dog:
    def __init__(self, name, age):
        # self stores the data on the object
        self.name = name
        self.age = age

    def bark(self):
        # self reads data from the same object
        print(f"{self.name} says woof!")

my_dog = Dog("Max", 3)
my_dog.bark()

Output:


Max says woof!

Notice that bark takes only self. When we call my_dog.bark(), Python passes my_dog as self automatically.

If you are still learning how constructors work, the article on the Python init and self: a clear guide explains how they work together.

How Self Connects to Objects

Every object has its own set of attributes. Self is the bridge between a method and those attributes.

Let's create two objects and compare them:


class Car:
    def __init__(self, brand):
        self.brand = brand

    def show(self):
        print(self.brand)

car1 = Car("Toyota")
car2 = Car("Ford")

car1.show()
car2.show()

Output:


Toyota
Ford

Both objects use the same method. But each call uses its own self. So each object shows its own brand.

This is the core idea. Self makes methods work on the correct object.

Self in Classes vs. Functions

A regular function does not use self. It simply takes the arguments you give it.

A method inside a class uses self to work with the object. This difference is important for beginners.

If you define a method inside a class and forget self, Python will raise an error when you call it. The method will not know which object to use.


class Counter:
    def __init__(self):
        self.count = 0

    def add(self):
        # self keeps the count on the object
        self.count += 1
        return self.count

c = Counter()
print(c.add())
print(c.add())

Output:


1
2

Because self points to the same object each time, the count keeps growing. If self were missing or wrong, the count would reset or fail.

For a deeper look at how methods are defined in classes, read about the Python self parameter in classes.

Common Mistakes with Self

Beginners often make a few common errors with self. Knowing them early saves time.

Mistake 1: Forgetting self in the method definition. Python will complain about missing arguments.

Mistake 2: Forgetting self when using an attribute. Writing name = name instead of self.name = name creates a local variable, not an attribute.

Mistake 3: Passing self manually. You should not do this. Python handles it for you.

Mistake 4: Using self outside a class method. Self only makes sense inside an instance method.

These mistakes are normal for beginners. With a little practice, they disappear quickly.

Self and Class-Level Data

Self gives access to instance data. Sometimes you also need class-level data. That is where cls comes in, but that is a topic for another day.

For now, remember that self always refers to the instance. It never refers to the class itself.

This distinction helps you understand why different objects can hold different values while sharing the same methods.

Self in Inheritance

Self also works with inheritance. A child class can use self to access attributes defined in a parent class.

When a child method runs, self refers to the child object. That object includes both child and parent attributes.

This makes self very powerful. It keeps methods flexible and reusable across related classes.

Is Self Optional?

Technically, you can name the first parameter anything. Python does not care. But you should always use self.

Using another name confuses readers. It also breaks a convention that every Python developer expects. Stick with self for clean, readable code.

Quick Summary

Self is a reference to the current object. It lets methods read and change that object's data.

Python passes self automatically. You define it as the first parameter of instance methods.

Self is central to classes, objects, and constructors. It is one of the most important concepts in Python object-oriented programming.

Practice with small classes. Create objects. Watch how self connects each method call to the right object. The idea will click fast.

Conclusion

Self in Python is simple once you see it in action. It is the link between an object and its methods. It lets every object keep its own data while sharing common behavior.

Remember these key points: self refers to the current instance, Python passes it automatically, and you should always name it self. Avoid common mistakes like forgetting self in method definitions or attribute assignments.

With clear examples and a bit of practice, self becomes second nature. It opens the door to writing clean, reusable, object-oriented Python code.