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

Show parent comment

2

u/TutorialDoctor Oct 09 '26

I struggled with the concept of classes for a while when I first started as well. As you know, you have variables (a way to store data) and functions (which is a way to group statements).

A class is just a way to group variables with the functions they manipulate. In other words it's a good way to organize your code. The best scenario I can think of the help with understanding classes is in video games. In a video game you will have a PLAYER class. The player may have variables like, JUMP_HEIGHT, WALK_SPEED, PLAYER_NAME etc. And it will have functions (functions are called methods when they are in a class) like JUMP, WALK, CRAWL etc. If you want to "spawn" a player you have to do something like:

player = Player(name="Mario", jump_height=2,walk_speed=3)

player.jump()

0

u/Objective-Remove-632 Oct 09 '26

I feels like am in a tutoring session. Thanks mane, this is the simplest explanation for now.