Skip to content
BENIBIX Learn

Method vs Function

A method is a function too, but it belongs to an object. A plain function stands alone; a method is called with a dot and can use its object's data.

Development🧭 Programming Paradigms

Method (Programming)

A function that belongs to an object. It can use that object's data.

A method is a function that belongs to an object or a class. It can read and change that object's own data. You call it with a dot after the object, like rex.speak() or "hello".upper(). The same method name can do different things on different kinds of object. In Python, a method's first input is usually called self, which means the object itself.

Example
Lucy calls upper() on the word hello. The string method gives back HELLO, and the original word is unchanged.
Why it matters
Methods keep each action next to the data it works on. That makes code easier to find and change.
Full entry
Development🧩 Programming Concepts

Function

A named block of code that does one job. Write it once, use it many times.

A function is a named block of code that does one job. You write it once and then use it as often as you like. It can take values in, called parameters, and hand a result back. Calling it by name runs the code inside. Splitting a program into small functions makes it easier to read, test and fix.

Example
A shop writes one function, add_tax, that adds 20% to a price. Every page that shows a price calls it.
Why it matters
Functions stop you writing the same code twice. Fix a bug in one function and every place that uses it is fixed.
Full entry

In one line

Method (Programming)
A function that belongs to an object. It can use that object's data.
Function
A named block of code that does one job. Write it once, use it many times.