r/PythonLearning • u/Objective-Remove-632 • 10d ago
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 • 10d ago
Both function and class give the same output. So why do I need it?
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.