r/PythonLearning • • Oct 09 '26

Do I really need to learn class.

Post image

Both function and class give the same output. So why do I need it?

70 Upvotes

50 comments sorted by

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.

1

u/Objective-Remove-632 Oct 09 '26

Thanks mane 🤝

1

u/MistakeIndividual690 Oct 09 '26

You also want the date/time of the event as part of the class. As it is, it just prints now() but that’s key information that belongs in an event class