Object-oriented programming (OOP) is a very popular paradigm. Objects are created using classes, which are actually the focal point of OOP. A class is an object’s description. Of course, you can use the same class as a blueprint/description for creating multiple different objects.
Classes are created using the keyword class and an indented block, which contains class methods (which are functions).
class Motor: def __init__(self, color, engine): self.color = color self.engine = engine honda = Motor("red", 125) yamaha = Motor("blue", 150) suzuki = Motor("orange", 250)
We defined a class named
Motor, which has two attributes:
Then the class is used to create 3 separate objects of that class.