Why Python Uses 'Self' as Default Argument (original) (raw)

Last Updated : 20 Sep, 2025

In Python, when defining methods inside a class, first parameter is always self. It is not a keyword, but a naming convention that plays a key role in Python’s object-oriented programming. The self parameter represents instance of the class itself, allowing you to access and modify its attributes and methods.

Code shows how self is used to store data in an object and access it through methods.

Python `

class Car: def init(self, brand, model): self.brand = brand # Set instance attribute self.model = model # Set instance attribute

def display(self):
    return self.brand, self.model

Create an instance of Car

car1 = Car("Toyota", "Corolla")

Call the display method

print(car1.display())

`

Output

('Toyota', 'Corolla')

**Explanation:

Now, Let's understand why python uses self.

Why use Self?

The main reason Python uses self is to make object-oriented programming explicit rather than implicit. By requiring the instance of the class as the first parameter, Python ensures:

Why Not Implicit?

Unlike some other programming languages, Python doesn’t hide this reference automatically. This makes it clear and unambiguous that the method is operating on an instance of the class, which improves readability and avoids confusion (especially in inheritance).

Object Initialization & Method Invocation

In this example, self is used to initialize an object’s topic and access it inside a method.

Python `

class gfg: def init(self, topic): self._topic = topic # Store parameter value in instance variable

def topic(self):
    print("Topic:", self._topic)  # Access the renamed variable

Creating an instance of gfg

ins = gfg("Python")

Calling the topic method

ins.topic()

`

**Explanation:

Circle Class for Area Calculation

Below example shows how self is used to access attributes of the correct instance while performing calculations.

Python `

class Circle: def init(self, r): self.r = r

def area(self):
    a = 3.14 * self.r ** 2
    return a

Creating an instance of Circle

ins = Circle(5)

Calling the area method

print("Area of the circle:", ins.area())

`

Output

Area of the circle: 78.5

**Explanation: