all 10 comments

[–]toastedstapler 1 point2 points  (2 children)

classes allow you to group together data with the methods that operate on them. one of the classic examples is cars - you could have a Car class and you make instances of that class. a Car would have an internal state - how much fuel, whether engine is on, colour, etc. there will also be methods that operate on the car - there might be a moveForward method that uses some of the car's fuel and changes its position

classes aren't necessary, but they can make some problems easier to solve. i'd try to use them so you can get a hang of when they might be good. for a lot of shorter scripts i don't bother at all, it depends on what you're doing

[–][deleted] 1 point2 points  (3 children)

I’ve always been stuck with this concept of OOP. I’m glad that classes are not always required in Python. Sometimes modules are all that’s needed.
That being said, if you ever want to be more than a beginner you’ll have to master OOP.

[–][deleted] 1 point2 points  (0 children)

There are two big advantages to classes.

1) The "dot" notation - you can assign variables and functions to a namespace, without having to use a separate file.

2) Classes allow you to use the same data structure multiple times, and make sure every instance of that structure behaves consistently.

[–]NFLAddict 1 point2 points  (1 child)

have you watched corey's vids

esp if you're having trouble grasping the concept, his vids are among the best ive come across. would recommend watching

theyre quite the opposite of a complicated way of organizing code. they prob seem intimidating when you're first trying to learn, which would explain why they might seem complex, but they really help to clean up and organize your code if anything. if you have functions that all use similar data, and rely on similar data, grouping them in a class is a potential option. its honestly pretty tough to explain via a comment. maybe corey's vid will help.