0
1

[–] WolfSheep 0 points 1 points (+1|-0) ago  (edited ago)

Sometimes, you need a bunch of functions to operate on some sort of shared state. Lets use a internet connection for example. Lets say you have a few functions you want to be able to use on a given internet connection; open, close, send data, and receive data. You don't want to send or receive data when the connection's state is closed, so you encapsulate all of this into a class. The class keeps track of the state of the internet connection. Some things it could store are the internet address (IP) for the connection, what port to connect to, and whether the connection is open or closed. It becomes quite convenient to wrap this all up in a class. Once you have you can create a connection object from the class's init method, open the connection, send and receive data, then close the connection and juggle more than one connection by assigning them all to different variables. In fact, this is exactly how sockets (internet connections) work in Python.

0
1

[–] springingski 0 points 1 points (+1|-0) ago 

I suggest you look at other peoples code, if it is of good quality and not just a very short script its likely to have quite a lot of classes in it. Think about what you'd need to do to replace its usage of a class and its objects. Yes, often it might be possible by just having functions and using the built in data-types, but what classes and objects do for you is make the code much clearer once you understand how they work. Also in python many advanced coding techniques rely on features which are available with classes, e.g. look at the end of this video:

https://www.youtube.com/watch?v=WjJUPxKB164