Python Functions vs Methods (Method Objects)
Object
An object is an instance of a class that contains data (attributes) and behavior (methods).
Here’s a clear, interview-ready explanation you can give at Google (or any top tech interview):
Python function
- A function is defined independently (not inside a class).
- It does not belong to any object.
- You call it directly by name.
def add(a, b):
return a + b
add(2, 3)
Key points to say:
- Lives in a module or global scope
- No automatic
self - Called as
function(args)
Method (Method Object)
- A method is a function defined inside a class.
- When accessed via an instance, Python binds it to the object → this creates a method object.
- The instance is automatically passed as
self.
class Calculator:
def add(self, a, b):
return a + b
c = Calculator()
c.add(2, 3)
What’s happening internally:
Calculator.add→ functionc.add→ bound method object- Python automatically passes
casself
Equivalent to:
Calculator.add(c, 2, 3)
Core Differences
| Aspect | Function | Method Object |
|---|---|---|
| Defined | Outside class | Inside class |
| Belongs to | Module | Object / Class |
self |
No | Yes (auto-passed) |
| Accessed via | func() |
obj.method() |
| Binding | Not bound | Bound to instance |
“In Python, a function is an independent callable, while a method object is a
function bound to an instance, where the instance is automatically passed as
self.”
Summary
Class.method→ functioninstance.method→ bound method@staticmethod→ function inside class, no binding@classmethod→ bound to class, getscls
Further Reading