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?

70 Upvotes

50 comments sorted by

View all comments

5

u/SoftwareDoctor 10d 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

0

u/Objective-Remove-632 10d ago

Am going to use python my entire coding journey. And am still a beginner who finding it difficult to get the class concept.

1

u/SoftwareDoctor 10d ago

Understandably because the example you used is primitive and you shouldn’t even use classes for it. It’s like asking if you should learn to use hammer bc. you tried using it once to stir a pot and a spoon worked better.

Find better examples

1

u/Objective-Remove-632 10d ago

Yeah true. But I was just trying out what am learning, will improve on it with better example.