A Python method is basically a function; both of them perform a specific task by taking some input, processing it, and producing some output. However, the difference between the two consists in the input that they can take. In fact, a method is a function defined inside a class and consequently, its input is restricted to that data type. On the other hand, a function doesn’t have this restriction because it is an independent entity and theoretically, it can take any data type as input.
A Python method is a function defined inside a class.
To better understand methods, we will return to the car racing example. To control the speed of the car, we would probably define two methods named accelerate() and brake() inside the “Car” class. Just like functions, these methods will perform some tasks, however, their input will be restricted to the “Car” data type. We say that these methods are associated with the “Car” data type.
In the Python Classes section it was mentioned that “a class defines the data that each object will contain, in addition to other information”. The term “other information” here means methods, so, a class combines data and methods into one entity. For example, the “Car” class can be defined as follows: