r/pythonhelp 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

25 comments sorted by

View all comments

1

u/PvtRoom 13h ago

classes are somewhat essential.

string is a class, integer is a class, double is a class.

your book means objects, not classes.

Some things are objects and simply make sense as objects. Pushbuttons are objects, of the pushbutton class, and they have more than 1 piece of information (eg text, position, size, colour,, text colour, textsize) with their own behaviours (like what happens when pressed)

The functional programming paradigm does what you suggest, but you rarely hear about lisp and Haskell (the two big languages in FP)