# Understanding self in Python OOP: A Beginner Friendly Guide

%[https://www.youtube.com/watch?v=FPuoJmL6LTg] 

One of the biggest "roadblocks" for Python beginners is the `self` keyword. You see it in almost every class, it’s the first argument in every method, and yet, we don't seem to pass any value to it when we call the function.

If you’ve ever wondered:

* What does `self` actually do?
    
* Why do I have to type it every single time?
    
* How does Python know which object I’m talking about?
    

Then this Blog is for you. Let’s break it down.

## What is a Class and a Method?

Before we talk about `self`, remember the relationship between a **Class** and an **Object**.

* **Class:** A blueprint (like a drawing of a house).
    
* **Object (Instance):** The actual house built from that blueprint.
    

If you build five houses from the same blueprint, they all have the same structure, but they have different owners and different furniture inside. `self` is the way the house "identifies" itself.

```python
class User:
    def set_email(self, email):
        self.email = email
```

Here:

* `User` → Class
    
* `set_email()` → Method
    

## What is `self`? (The Simple Definition)

`self` represents the specific instance (object) of the class.

When you define a method inside a class, Python needs a way to distinguish between different objects.

```python
class Robot:
    def introduce(self):
        print(f"Hello, I am {self.name}")
```

In the code above, [`self.name`](http://self.name) tells Python: *Look for the name attribute inside THIS specific robot, not all robots in the world.*

## The Secret Behind Method Calls

This is where most beginners get confused. Look at these two ways to do the exact same thing:

### Method 1: The Manual Way (Internal)

```python
User.set_email(user1, "ammad@hasab.tech")
User.set_email(user2, "shameel@hasab.tech")
```

In this way:

* We manually pass the object
    
* `user1` becomes `self`
    
* This helps us understand what Python does internally
    

### Method 2: The Pythonic Way (Standard)

```python
user1.set_email("ammad@hasab.tech")
user2.set_email("shameell@hasab.tech")
```

Behind the scenes, Python converts this into:

```python
User.set_email(user1, "amma@hasab.tech")
```

That’s why:

* This method is simpler and mostly used in real projects
    

## How `self` Works with Different Objects

When this line runs:

```python
user1.set_email("ammad@hasab.tech")
```

* `self` → `user1`
    
* [`user1.email`](http://user1.email) → `"`[`ammad@hasab.tech`](mailto:amma@hasab.tech)`"`
    

When this line runs:

```python
user2.set_email("shameel@hasab.tech")
```

* `self` → `user2`
    
* [`user2.email`](http://user2.email) → `"`[`shameel@hasab.tech`](mailto:shamil@hasab.tech)`"`
    

This shows that self ensures each user instance uses it’s own data or value, which is the core idea of Object Oriented Programming.

## Why `self` Is Important

`self` allows Python to:

* Identify **which object is calling the method**
    
* Store data **separately for each object**
    
* Avoid data overwriting between objects
    

Without `self`, Python would not know where to store object-specific values.

## Common Beginner Mistakes

* Thinking `self` is a keyword (it’s not, but it’s a strong convention)
    
* Forgetting to add `self` as the first parameter
    
* Confusing instance variables with class variables
    

Always remember:

```python
self.variable_name
```

means the variable belongs to **that specific object**.

## Summary

* `self` represents the **current object** in Python
    
* It helps Python identify **which object is calling a method**
    
* A method can be called in **two ways**:
    
    * Using class name (manual)
        
    * Using object name (automatic and common)
        
* `self` changes depending on the object calling the method
    
* It allows each object to maintain **its own data independently**
    

Understanding `self` is a **foundation of Python OOP**, and once you grasp it, many advanced concepts become much easier.

***Stay connected with hasabTech for more information:***

[**Website**](https://hasab.tech/) [**| Facebook**](https://www.facebook.com/hasabTech) [**| LinkedIn**](https://www.linkedin.com/company/hasabtech) [**| YouTube**](https://youtube.com/@hasabTech) [**| X (Twitter)**](https://x.com/hasabTech) [**| TikTok**](https://tiktok.com/@hasabTech)
