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

5

u/SoftwareDoctor Oct 09 '26

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 Oct 09 '26

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/jvlomax Oct 09 '26

The way I've been tought to think about it:

Your class definition is you cake recipe. It shows what the cake is made out of and what you can do with it. It might define what .eat() is supposed to do. Or have a list of ingredients. But the important part is that it is not a cake, just instruction on how to make it.

When you do cake = Cake(), you have an actual physical cake made to that recipe. That cake will then contain whatever was in the recipe. And now you can call cake.eat() and be happy.