Python · Object-Oriented Python

Class vs object

Mediumclassobjectinstanceoop

Interview question

What is the difference between a class and an object?

How to answer

The short answer

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 like name and methods like bark().
  • 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.

Python
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.

Lock it in with a real drill

You remember an answer longer once you have used it. Try a hands-on problem on this concept.

Open related drill