self is the conventional name for the first parameter of an instance method in Python. When you call obj.method(), Python passes obj into the method as that first argument, so the method can read and change the attributes of that specific instance. self is not a reserved keyword: it is a naming convention that every Python style guide, including PEP 8, expects you to follow.
Because Python methods are plain functions stored on the class, the instance has to be passed in explicitly. That is the reason self appears in the method signature but not in the call.
A function defined inside a class body is an ordinary function. When you access it through an instance, Python wraps it in a bound method that automatically supplies the instance as the first argument.
The two calls are equivalent. alice.greet() is shorthand for Person.greet(alice), which shows that self is just the first positional argument.
Attributes assigned on self belong to one instance. Names assigned without self are local variables that disappear when the method returns.
Each object keeps its own value. If increment wrote to a bare value instead of self.value, Python would raise UnboundLocalError because it would treat value as a local name.
An attribute defined directly in the class body is shared by all instances. Reading it through self works, but assigning through self creates a new instance attribute that shadows the class one.
Inside a class, you reach sibling methods through self. A bare function name is looked up in the module scope, not in the class.
Calling subtotal() without self. inside total would raise NameError.
self refers to the actual object, which can be an instance of a subclass. This is what makes method overriding and super() work.
In a subclass, super().__init__(...) calls the parent initialiser and passes the same self automatically, so you do not write super().__init__(self, ...).
Not every method receives an instance. The first parameter depends on the decorator.
| Method kind | Decorator | First parameter | Typical use |
|---|---|---|---|
| Instance method | none | self (the instance) | Work with one object's state |
| Class method | @classmethod | cls (the class) | Alternative constructors, class-level state |
| Static method | @staticmethod | none | Utility function grouped with the class |
self in the signature. def greet(): inside a class fails with TypeError: greet() takes 0 positional arguments but 1 was given when called on an instance.self. when reading an attribute. The name is looked up as a local or global and raises NameError.self inside a method. This only rebinds the local name and does not change the caller's object.items = [] in the class body, which all instances then share.No. It is a convention. You could name the parameter this and the code would run, but linters and other developers expect self, so you should always use it.
The language follows "explicit is better than implicit". Making the instance an explicit parameter keeps methods as plain functions and makes the difference between local variables and attributes obvious.
Only if you pass an instance yourself, as in Person.greet(alice), or if the method is a class method or static method.
self is the instance the method was called on. cls is the class itself and is used in @classmethod methods.
self is the explicit first parameter of instance methods and refers to the object the method was called on. Use self.name to store and read per-instance state, self.method() to call sibling methods, and cls or no first parameter for class and static methods. It is a strong convention, not a keyword, and following it keeps your code readable and compatible with tooling.