self is the conventional name for the first parameter of an instance method in Python. When you call obj.method(arg), Python automatically passes obj as the first argument, so the method receives it as self. Inside the method, self.x accesses the instance attribute x, and self.other_method() calls another method on the same instance.
Unlike this in Java or C++, self is not a reserved keyword in Python — it is purely a naming convention. You could name it anything (and the code would still work), but using any name other than self is considered a serious violation of Python style and will confuse every reader of your code. PEP 8 explicitly mandates self for instance methods and cls for class methods.
The explicit self parameter is a deliberate design choice by Guido van Rossum. It makes the object-oriented mechanism transparent: you can see exactly how methods are ordinary functions that receive the instance as their first argument. It also means that methods can be extracted from their class and called as regular functions, passed around as callbacks, or bound to different objects — the "self" is just a parameter, not magic.
Discussed in:
- Chapter 9: Classes and Objects — The __init__ Method and self