100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Python

self Keyword in Python

Why self appears as the first parameter of instance methods and how it links a method call back to its object.

OOP BasicsBeginner8 min readJul 7, 2026
Analogies

1. Introduction

self is the conventional name for the first parameter of every instance method in a Python class. It represents the specific object the method is being called on, giving the method access to that object's attributes and other methods. Without self, a method would have no way to know which instance's data to read or modify.

🏏

Cricket analogy: Just as a specific batter's stance is unique to them and not the whole team, self lets a method like score_run() know it's Kohli's innings data being updated, not some generic player's.

When you write obj.method(arg), Python automatically passes obj as the first argument to method, which is why the method's definition includes self as its first parameter even though you don't pass it explicitly at the call site.

🏏

Cricket analogy: When you call kohli.bat(ball), it's as if the scorer automatically writes "Kohli" on the scorecard before recording the shot — Python passes kohli into self the same way.

2. Syntax

python
class ClassName:
    def __init__(self, value):
        self.value = value       # self refers to the instance being created

    def show(self):
        return self.value        # self accesses this instance's attribute


obj = ClassName(10)
obj.show()                       # equivalent to ClassName.show(obj)

3. Explanation

Every regular method defined inside a class must declare self as its first parameter. When called via obj.method(args), Python's attribute lookup mechanism (the descriptor protocol) automatically binds obj to self, so the call becomes equivalent to ClassName.method(obj, args). This is how a method knows exactly which object's attributes to operate on.

🏏

Cricket analogy: The umpire's decision review system automatically links a review request to the specific batter under review, just as Python's descriptor protocol binds the calling player (obj) to self when kohli.review() is called.

Inside a method, self.attr = value creates or updates an attribute on that specific instance, and self.method() calls another method on the same instance. This is how objects maintain and manipulate their own independent state.

🏏

Cricket analogy: When Kohli's method updates self.runs += 4, it's like the scorer crediting the boundary only to Kohli's individual tally, and self.celebrate() is Kohli calling on his own bat-raise routine, not another batter's.

self is not a reserved keyword in Python — it is purely a naming convention. You could technically name the first parameter anything (e.g., this, obj), and the code would still work, because Python binds the instance to whatever name is listed first. However, every Python developer expects self, and deviating from it makes code confusing and violates PEP 8.

Forgetting to include self as the first parameter of an instance method — or forgetting to pass it when calling via the class (ClassName.method(obj)) — is a common source of TypeError: missing 1 required positional argument errors. Static methods (@staticmethod) are the exception: they intentionally omit self because they don't operate on a specific instance.

4. Example

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

    def increment(self, step=1):
        self.count += step
        return self.count


c1 = Counter()
c2 = Counter(100)

print(c1.increment())
print(c1.increment(5))
print(c2.increment(10))

# Calling the method explicitly through the class, passing the instance manually
print(Counter.increment(c1, 2))
print("this_name_works_too:", (lambda that: that.count)(c1))

5. Output

text
1
6
110
8
this_name_works_too: 8

6. Key Takeaways

  • self refers to the specific instance a method is operating on.
  • obj.method(args) is automatically translated to ClassName.method(obj, args) by Python.
  • self is a naming convention, not a reserved keyword — but you should always follow it.
  • Inside a method, self.attr reads or writes that instance's own attribute.
  • Static methods deliberately omit self because they don't act on a particular instance.

Practice what you learned

Was this page helpful?

Topics covered

#Python#PythonProgrammingStudyNotes#Programming#SelfKeywordInPython#Self#Keyword#Syntax#Explanation#StudyNotes#SkillVeris