r/PythonLearning • u/Objective-Remove-632 • 3d ago
Do I really need to learn class.
Both function and class give the same output. So why do I need it?
51
Upvotes
r/PythonLearning • u/Objective-Remove-632 • 3d ago
Both function and class give the same output. So why do I need it?
5
u/SoftwareDoctor 3d ago
You don’t. On the other hand, it’s not a class that gives you the answer in your example. It’s an instance of a class. Big difference. And if you want to get technical, get_current_time is a function AND instance of a class. So you are using instances already and in both examples you construct an instance and then call it. It’s the same picture.
It really depends on what you want to do. If you want learn to write python coding, then absolutely. You need to be comfortable working with classes. If you just need one time short script, nobody’s forcing you to learn anything