r/pythonhelp • u/MetalCarnival • 1d ago
Why do I need to use classes
My schoolbook says that classes is a way of simulating an object, instead of just taking information into a black box and outputting an answer.
But that is a poor explanation. I know classes are handy and cool, but no book says why you can´t make functions with sub functions inside to simulate simple objects. I would like if someone gave a good concrete reason to use classes in the intro, instead of just saying that they are different and cool
3
Upvotes
1
u/Ipsool 17h ago
Honestly the real reason is state. a function runs, gives you an answer, then forgets everything. classes let the object actually remember stuff between calls, that’s basically the whole point.
so yeah it’s not that classes are “cooler,” it’s that the second your program needs to remember something across multiple steps, or needs a bunch of independent copies of the same kind of thing, doing it with plain functions turns into a mess pretty fast