Python Basics Exercises: Object-Oriented Programming (Overview)

In Python Basics: Object-Oriented Programming, you learned how OOP, or object-oriented programming, is a method of structuring a program by bundling related properties and behaviors into individual objects.

In this video course, you’ll practice the following:

  • Create a class, which is like a blueprint for creating an object
  • Use classes to create new objects
  • Instantiate classes with attributes and methods
  • Use dunder methods like .__init__() and .__str__()

This video course is part of the Python Basics series, which accompanies Python Basics: A Practical Introduction to Python 3. You can also check out the other Python Basics courses.

Note that you’ll be using IDLE to interact with Python throughout this course.


Sample Code (.zip)

1.7 KB

Course Slides (.pdf)

7.8 MB

00:00 Welcome to this Real Python Exercises course where you’ll practice using object-oriented programming in Python. Our exercise courses are all about training.

00:09 You’ll train the process of writing code by solving carefully selected exercises. You’ll also train in reading other people’s code and communicating your thought process. Doing all that, you’ll practice the concepts that you’ve learned about in an associated course or tutorial and help make them stick. So, in the upcoming lessons, I’ll introduce you to tasks, give you an opportunity to solve them yourself, and then show you step by step how I solved each of them.

00:33 So, you’ll go through three steps for each task. You’ll first learn about the exercise, you’ll code your own solution. Then, you’ll compare your solution and the process that got you there to mine.

00:45 When I walk you through a task, I’ll explain what I am doing and also why I am doing it like that. That’ll give you a chance to compare not just our final solutions, but also how we got there.

00:54 This can help you gain some insight on the process of getting from a task description to a working solution in code.

01:00 You’ll start by solving some review exercises in the first section of this course and build up towards a challenge. In the second section, you’ll continue to train in creating classes in Python.

01:09 The challenge in this course will be similar, but less based on what you did before. It’ll give you a chance to revisit the fundamental OOP concepts and yet another example. Before starting this course, you should have watched the Python Basics course on object-oriented programming. If you went through that course, then you’re well equipped to solve the tasks that you’re about to encounter.

01:30 The concepts that you’ll practice are: the difference between classes and instances, how to define a class, what class attributes are,

01:43 and also how to create some special methods that are also called dunder methods. And finally, also f-strings. If you’re already somewhat familiar with these concepts, but you want to fortify your knowledge with practical programming tasks, then this course is exactly right for you. Before you get started, there’s another tiny bit of background for this course, which is that I’ll be using IDLE, the Integrated Development and Learning Environment that comes with Python.

02:10 If you’ve gone through the Python Basics courses, then you’re already familiar with that tool. If not, and you want to know more, then you can check out these associated courses that cover getting started with IDLE. I’ll use IDLE’s interactive console.

02:22 That gives you direct access to the code defined in the Python file you executed. This makes it a bit more interactive when testing the code, but you don’t need to use that feature, and you can replace it with print() calls at the end of your file. So, if you’re just here to train, then feel free to use whatever tool you like to solve the upcoming coding tasks.

02:43 And that’s all to get you set up. If you’re ready to get started and do hands-on programming, then see you in the next lesson. I’ll introduce you to the first exercise to get you warmed up, and I hope that you won’t pass on either the review exercises or the challenges.

Become a Member to join the conversation.