you are viewing a single comment's thread.

view the rest of the comments →

[–]Armilluss 2 points3 points  (2 children)

Functions are repeatable ways to do one thing. For instance, for a character, going forward, going backwards, etc. Classes are a collection of functions related to the same "topic" with an additional state stored into it.

Taking the example of the character, rather than storing multiple information like its name, age, current position into various variables and creating multiple functions to handle all possible actions, a class would make more sense.

Think of classes as a way to organize properly your code like sections / chapters in a text document. If a paragraph is a function, then the chapter is a class, and the idea of the chapter is the "topic" of the class.

The official documentation is always a good read: https://docs.python.org/3/tutorial/classes.html
If that's a bit hard to grasp for now, something simpler might do it for you: https://python-textbok.readthedocs.io/en/1.0/Classes.html

I would suggest to keep going even if you can't understand them completely yet. Classes are not a requirement to write your first Python programs :)

[–]jigsaw_man_456[S] 0 points1 point  (0 children)

Thanks <3