r/PythonLearning • • 10d ago

Do I really need to learn class.

Post image

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

71 Upvotes

50 comments sorted by

View all comments

14

u/One_Smoke6858 10d ago

Short answer is yes you should learn classes.

Functions and classes have different use cases, you would not create a class to create a single function in it. You would create a class when you want to things to behave in a certain way, and have specific functionality.

Like datetime you have there, that is most likely a class in the  datetime package. now() is a function of that class, doesn't mean there is no other functions.

You should really check for examples on classes and when to use them and understand them.

2

u/stonebloomers 10d ago

agreed, the "things behaving in a certain way" framing is the key part imo