Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. Class vs object

Python · Object-Oriented Python

Class vs object

Mediumpython-21
classobjectinstanceoop

Question

What is the difference between a class and an object?

Solution

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.

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.

🎯 Put this concept into practice

Solidify this answer with real hands-on interview drills in the browser studio.

Open related drill →
PreviousNext