Browse OOP reference
Objects and behaviour

What is a method?

On this page

A method is an operation associated with a type or object. When Python evaluates cart.add(item), an ordinary instance method receives cart as its first argument. The same method body can therefore inspect a different cart on each call. Static methods and class methods use different binding rules.

Worked example

Python
class Counter:
    def __init__(self):
        self.count = 0

    def record(self):
        self.count += 1

counter = Counter()
record = counter.record
record()
assert record.__self__ is counter
assert counter.count == 1

Python tutorial on classes

Explore class relationships in the OOP Playground

What is multiple inheritance?What is method overloading?What is a class?

All OOP questions

Search ObjectFAQ