Class blueprint
1class Car: # Template
2def __init__(self, color):
3self.color = color
4def drive(self):
5print(f"{self.color} car driving")
Understand the distinction between a class (the template) and objects (the concrete things created from that template).
Each object has its own attributes. Methods use self to mean this object.
Class: A blueprint or template that defines what properties and methods an object can have. Written once in code.
Object: A concrete instance created from that class. You can create many objects from one class.
classDiagram
class Car {
-color: str
+__init__(color)
+drive()
}
Car : drive()
Car : color
car1 : Car
car2 : Car
Car <|-- car1
Car <|-- car2
A class is like a cookie cutter — the template. Each cookie you make with that cutter is an object — a unique instance. All cookies have the same shape, but each one is independent.