Skip to content

self (argument)

In Python, self is a widely followed convention for naming the first argument in instance methods within a class. It represents the instance on which the method is being called, allowing access to instance attributes and methods.

When defining instance methods, the self argument provides access to the instance. This allows the method to modify the instance’s state and differentiate instance variables from local variables inside methods. While you must explicitly declare self in method definitions, Python automatically passes the instance to methods when you call them.

Example

Here’s an example demonstrating self in a class:

Language: Python Filename: dogs.py
class Dog:
    def __init__(self, name):
        self.name = name

    def speak(self):
        print(f"{self.name} says Woof!")

# Usage
dog = Dog("Buddy")
dog.speak()  # Output: Buddy says Woof!

In this example, self.name = name assigns the name attribute to the instance. When you call dog.speak(), Python implicitly passes dog as self, allowing the method to access self.name and print the expected output.

OOP in Python 3

Tutorial

Object-Oriented Programming (OOP) in Python

Learn object-oriented programming in Python: the OOP paradigm, classes and inheritance, and how to instantiate objects from a class.

intermediate python

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Sept. 2, 2026 • Reviewed by Martin Breuss