2.17METHODS
Introduction to Python Methods
You are aware of the fact that Python is an object-oriented language, right? This means that it can deal with classes and objects to model the real world. A Python method is a label that you can call on an object; it is a piece of code to execute on that object.
Python Class Method
A Python class is an Abstract Data Type (ADT). Think of it as a blueprint. A rocket is made by referring to its blueprint, that is, according to its plan. It has all the properties mentioned in the plan and behaves accordingly. Likewise, a class is a blueprint for an object. For example, consider a car. The class “Car” contains properties like brand, model, color, and fuel. It also holds behavior like start(), halt(), drift(), speedup(), and turn(). An object Hyundai Verna has the following properties:
brand: ‘Hyundai’
model: ‘Verna’
color: ‘Black’
fuel: ‘Diesel’
Here, this is an object of...