A class is a blueprint: it defines attributes and behaviors. An object (instance) is a concrete value created from that blueprint.
- Class:
Dog, with fields likenameand methods likebark(). - Object:
Dog("Rex"), a specific dog in memory.
In Python, classes are themselves objects (of type type), which enables metaclasses and dynamic class creation, but interviews usually want the blueprint-vs-instance distinction first.
class Pipeline:
def __init__(self, name: str):
self.name = name
self.steps = []
def add(self, step: str) -> None:
self.steps.append(step)
etl = Pipeline("orders_etl") # object / instance
etl.add("extract")
etl.add("transform")
print(type(etl)) # <class '__main__.Pipeline'>
print(isinstance(etl, Pipeline))
print(etl.__class__ is Pipeline)One class → many independent objects, each with its own instance state.