top of page

Tips on learning Object-Oriented Programming (OOP) in Python

  • Writer: Suguru Chhaya
    Suguru Chhaya
  • Sep 3, 2020
  • 3 min read

Updated: Oct 23, 2020


Humans have different attributes like weight. They can also change their weight by eating food. I just explained attributes and methods in 2 sentences.



You have gotten the Python basics down and you are starting to build projects. You run into a bug and as usual, you visit Stack Overflow. But you see words like 'class', 'self', and '__init__' - all words you have never seen before. You don't what is going on and think, 'This must be too difficult for me.' You leave the page and start looking for answers again.


I have been in that position.


Object-Oriented Programming isn't extremely difficult for me (at least for now). But it is a new and advanced concept that is different from procedural programming.


Even though I learned the basics of OOP through a tutorial, I didn't exactly know how to use it in my code. I was frustrated in my lack of confidence in creating and using classes and objects, and I once tried to convert ALL my procedural programming code into OOP code. I OBVIOUSLY failed, and I was more confused than ever. When should I use OOP and when shouldn't I?


After some trials and errors trying to learn OOP, I can tell you that I am pretty working with classes and objects now. Learning OOP has tremendously improved my ability to read and understand code. I will explain the steps I recommend to learn OOP below.


Step 1: Learn the Basic Rules Through a Tutorial


Like every other programming concept I tried to learn, I first tried finding a tutorial online to learn OOP.


I started the "Objected-Oriented Programming in Python" course on Datacamp (https://www.datacamp.com/courses/object-oriented-programming-in-python). It wasn't a bad tutorial and I would recommend it to those who are new to OOP.


The key lessons I learned from this tutorial:


Unlike many beginner concepts in Python, you cannot use OOP well just by going through a tutorial. The step is necessary, but to be able to comfortably use classes and objects, you need practice, which makes it important to follow the steps below after you finish a tutorial.

Terminology isn't that important. I used to take notes of my tutorials on Jupyter Notebooks, and I used the new advanced terminology I learned from the tutorial because I felt smarter that way. When I looked back at the Notebooks today, I didn't know the meaning of half of the terminology in my notes. On the other hand, I completely understood what the example code I had written did. When learning concepts from a tutorial, I will recommend you to write good example code instead of writing long explanations using advanced terms.


Step 2: Make Guided Projects


In my opinion, this is the most important step in learning OOP. This is the step where you learn how to ACTUALLY use OOP in your code.


Some courses/videos of guided projects I recommend:


Beginner: FutureLearn's "Object-Oriented Programming in Python: Create Your Own Adventure Game" (https://www.futurelearn.com/courses/object-oriented-principles).


Advanced: Tech With Tim's "Pygame Tutorial: Creating Space Invaders" (https://www.youtube.com/watch?v=Q-__8Xw9KTM) My initial intention for watching this video was to get started with Pygame, but I also strongly recommend this video to those you want to improve using OOP.


Step 3: Make Your Own Projects


Once you learn how to use OOP in the previous step, it is now time to be creative and work on your own projects.


Some projects I worked on:


Shopping list/calculator (https://github.com/SuguruChhaya/shopping_calculator) using Tkinter. This was the first project I made using a lot of OOP because every item had it's own properties (whether it is save mode or edit mode, whether the mouse is hovering over or not etc). Through making this project, I solidified my knowledge about what 'self' actually is, correct ways of passing arguments in methods, difference between creating an object and using a method etc. (I'm gonna drop a video on this project in the future. Subscribe to my YouTube Channel at https://www.youtube.com/channel/UCqnubua38JoJNCCADcG1s4w and follow me on Instagram: https://www.instagram.com/suguru_coding/)


2. Pygame projects in general. My favorite so far is the Mogura Tataki game (https://github.com/SuguruChhaya/mogura-tataki), which I have created a playlist on my YouTube channel (https://www.youtube.com/channel/UCqnubua38JoJNCCADcG1s4w). Pygame is a relatively easy library to learn after you get the basics down. Games obviously require a lot of objects, and I can tell from my personal experience that game development will help you improve your OOP skills.

Comments


bottom of page