What Is Object-Oriented Programming (OOP)?
In this video, you’ll learn what object-oriented programming (OOP) is and why it’s used.
Lots of popular frameworks and libraries are written using OOP, so it’s a good tool to have in your Python toolkit.
OOP is a programming paradigm, or a specific way of designing a program. It allows us to think of the data in our program in terms of real-world objects, with both properties and behaviors. These objects can be passed around throughout our program.
Properties define the state of the object. This is the data that the object stores. This data can be a built-in type like
int, or even our own custom types we’ll create later.
Behaviors are the actions our object can take. Oftentimes, this involves using or modifying the properties of our object.
00:00 Hi. I’m Austin Cepalia with realpython.com, and I welcome you to our series on object-oriented programming in Python 3. This is one of the biggest and most important subjects in all of programming and as you can see, we have a lot to cover.
00:16 This series will provide you with a basic conceptual understanding of object-oriented programming so that you can take your Python programming skills to the next level. To fully appreciate the subject, we have to first understand why we need it. Programs are very complex things and there’s a hundred different ways that you could define what a program is formally, but basically, all programs are a set of instructions for manipulating data in some meaningful way. When I teach Python to kids, I always have them write a program that calculates how many days old they are, and that’s a great example of a program that follows these three steps. First, the program has to ask the user for their birth date.
00:59 That’s the data it’s going to accept. Then, it manipulates the data by subtracting the current date from the user’s birth date. Finally, the program displays the result of this calculation on the screen.
01:12 That’s a great starter program, but it’s pretty trivial. How do we manage large programs with lots of data to keep track of, like a video game? As you might have guessed, that’s where object-oriented programming comes in.
01:26 Object-oriented programming, or OOP for short, is a very common programming paradigm. Informally, this means that it’s a specific way of designing programs, like a style that’s widely used in software projects.
01:41 Not every program should be written with OOP but many are, and lots of languages support it. A lot of the Python code you interact with on a daily basis will be written using OOP. Understanding this is a fundamental part of becoming a great Python programmer.
01:57 It opens the door to creating really cool software. At the heart of OOP is the idea that a program is composed of lots of individual objects. You can think of these objects as entities, or things, in your program.
02:12 Oftentimes, they are the nouns in your project, such as a person, a house, an email, or any other entity like that. These objects are like little bundles of data that are passed around throughout the life of your program. For example, a person might have properties like name, age, and home address.
This is the individual data that the object stores throughout its life in the program. When we create this
Person object, we’ll make sure to give it a name, an age, and an address. Objects also have behaviors. These are the actions that the object can take.
Our person should be able to walk, talk, and breathe, for example. Oftentimes, these behaviors will need to reference the properties of the object. For example, if we make our talk behavior print the name and the age of the person, then our
Person object would need to know what its name and age is—those properties we gave it earlier before.
03:12 If this all seems a little bit confusing right now, don’t worry. When I started programming, this was the first real hurdle I ran into, and it just took some dedication and practice until I finally understood it.
Become a Member to join the conversation.