# this and self

> The word a method uses to mean the object it was called on.

**Field:** Software Development  
**Category:** Programming Paradigms  
**Also known as:** this Keyword, self Parameter, self (Python)

## Think of it like

It is like saying "me" in class. The word stays the same, but it means whoever says it.

## Definition

this and self are words a method uses to mean the object it was called on. JavaScript, Java and C# use this. Python uses self, written as the first parameter of each method. When rex.bark() runs, self is rex. When bella.bark() runs, self is bella. That is how one method can work on many objects.

## Example

A bark method prints self.name. Called on Rex it says Rex. Called on Bella, the same code says Bella.

## Example code

```python
class Dog:
    def __init__(self, name):
        self.name = name
    def bark(self):
        print(self.name + " says woof")

Dog("Rex").bark()
# Rex says woof
```

self is the dog the method was called on. Here it is Rex.

## Why it matters

Without it, a method could not tell which object's data to use. Every class you write leans on it.

## Common mistake

Leaving out self as the first parameter in Python. The call then fails, saying it got one argument too many.

## Three principles

- **Means this object.** Whichever one the method ran on.
- **Two spellings.** this in most languages, self in Python.
- **Reaches the data.** Used to read and set properties.

## Related terms

- [Method (Programming)](https://learn.benibix.com/term/development/method)
- [Object (Programming)](https://learn.benibix.com/term/development/object)
- [Class](https://learn.benibix.com/term/development/class)
- [Property (Programming)](https://learn.benibix.com/term/development/property)
- [JavaScript](https://learn.benibix.com/term/development/javascript)
- [Python](https://learn.benibix.com/term/development/python)

![A card for a class named Dog. Its top part lists two properties, a public name and a private age. Its lower part lists a method, bark, that uses self.name, and a static method, count, marked as belonging to the class. Two dog objects, Rex and Bella, sit beside it, each with its own name. An arrow from self points at Rex.](https://learn.benibix.com/diagrams/dev7-class-parts.svg)

---

Source: https://learn.benibix.com/term/development/this-and-self
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
