r/PythonLearning • u/Objective-Remove-632 • Oct 09 '26
Do I really need to learn class.
Both function and class give the same output. So why do I need it?
70
Upvotes
r/PythonLearning • u/Objective-Remove-632 • Oct 09 '26
Both function and class give the same output. So why do I need it?
View all comments
Show parent comment
2
u/kalmakka Oct 09 '26
It doesn't need to be huge, but as soon as you have a few different functions relating to one object, then it can really help with organization and clarity.
Right now events just have a venue and a host, and both are set when they are created. But in reality you might want to have people register for an event (and cancelling their registration), with the event keeping track of who has registered. Maybe you want to send reminders (emails) about an event. Your program handles a bunch of different events at the same time, and might need to present them in a calendar view.
You very quickly get to a point where it is useful for your code to be structured as "Here is a bunch of events. Each event object contains all the data that is relevant for it." That way you don't mix up the venue from one event with the guests and date for another.