The Difference Between Methods and Functions

Because Python has both functions AND methods, let's look into the key differences between the two.

Python Methods
A method is a function that is a member of a class. For example: class SomeClass: def someMethod(self): print("Hello! I am a member of SomeClass.") thing = SomeClass thing.someMethod

Key Features

 * 1) Methods are called by name, but it is associated to an object (dependent).
 * 2) A method is implicitly passed the object on which it is invoked.
 * 3) It may or may not return any data.
 * 4) A method can operate on the data (instance variables) that is contained by the corresponding class.

Python Functions
A function is a block of code which only runs when it is called.

You can pass data, known as parameters, into a function. And a function can return data as a result. For example: def someFunction(name): print("Hello %s!" % name) someFunction("Renee") Hello Renee!
 * 1) Returns:

Key Features

 * 1) A function is a block of code that is also called by its name (independent).
 * 2) The function can have different parameters or may not have any at all. If any data (parameters) are passed, they are passed explicitly.
 * 3) It may or may not return any data.
 * 4) Functions do not deal with Classes and the concept of instances.