r/PythonLearning • u/Objective-Remove-632 • Oct 09 '26
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 • Oct 09 '26
Both function and class give the same output. So why do I need it?
View all comments
Show parent comment
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 callcake.eat()and be happy.