Method
A function that belongs to an object and is called on it with a dot, like text.upper().
A method is a function defined inside a class. Its first parameter is self, the particular object it was called on, so it can read and change that object's attributes.
You call a method with a dot and parentheses: account.deposit(50). Built-in types have methods too — "hi".upper() and [3, 1, 2].sort() are method calls.
class Counter:
def __init__(self):
self.total = 0
def add(self, n): # a method; self is this object
self.total += n
c = Counter()
c.add(5)
c.add(3)
print(c.total)
Output
8
Where this shows up in real Python
Methods are the behaviour attached to objects — text.upper(), items.append(x) — and the actions on your own classes.
Commonly used Method tools
obj.method()— call a method with the dotself— the instance the method belongs to@property— expose a method as if it were an attribute@staticmethod / @classmethod— methods not tied to one instance
Official documentation: Python Tutorial: Method Objects