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.
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.
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.
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.