What is the difference between a class and an instance?
Reveal the answer and explore the explanation.
01EasyCoreWhat is the difference between a class and an instance?
Answer
EasyCore
What is the difference between a class and an instance?
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 ↗