QUESTION 1 OF 10

What is the difference between a class and an instance?

Reveal the answer and explore the explanation.

01
EasyCore

What is the difference between a class and an instance?

Answer
Answer

A class defines a type and its behavior; an instance is a particular object of that type with its own state.

Practical example

Instantiate two preprocessing objects with different configurations.

PythonRelated concept example
from dataclasses import dataclass
@dataclass
class ModelConfig:
    threshold: float = 0.5
    def classify(self, probability):
        return int(probability >= self.threshold)
print(ModelConfig().classify(0.8))

Instance configuration is separate from class behavior.

Reference: Further reading ↗

Last 30 min revisionHigh-yield interview Q&As