r/learnpython • • Feb 23 '21

Classes. Please explain like I’m 5.

What exactly do they do? Why are they important? When do you know to use one? I’ve been learning for a few months, and it seems like, I just can’t wrap my head around this. I feel like it’s not as complicated as I’m making it, in my own mind. Thanks.

229 Upvotes

71 comments sorted by

View all comments

Show parent comment

5

u/BruceJi 📦 Feb 24 '21

When you write a class, it’s just the blueprints to that type of object. When you actually produce one, it’s going to have data there instead of an empty variable. This self keyword lets the class access its own data.

Python passes this in as the first object always. If you missed it out and you have other arguments, the first one is filled with self too. You don’t HAVE to call it self but between Pythonistas, self is used so everyone knows what it is