For this lesson on object-oriented programming in Python, we are going to take an introductory look at Python classes and we're going to see exactly how we can build a basic class analyze the syntax and then build it out.
Now that you know the basic syntax for creating a class and then a function inside of python in this guide we are going to extend that knowledge and we are going to see how we can add data.
When it comes to developing in object-oriented programming languages a couple terms that you are going to hear quite a bit of are going to be getter and setter functions.
In the last guide we walked through how we could get and set values inside of a python class but if you remember at the very beginning of the guide I mentioned how the practice of simply overriding and having access to all of the data inside of a class in the way that we did it just like how we were able to grab the data right here and how we're able to set it at any time this is considered in some circles a poor practice.
So far in this section, you've seen a few of the Dunder methods in Python.
In the last guide, we walked through the Dunder string method and the goal of Dunder string once again is to give some pretty output for the values and the details with our class.
So far in this section we've walked through a number of the Dunder methods that are available in python.
In the last guide, we walked through how we could build our own custom iterator. And we saw how we could leverage the tools such as Dunder iter and Dunder next in order to build out an infinite lineup and in many cases that will be the approach that you want to take whenever you need to build your own custom behavior into the iteration process.
Throughout this section on object-oriented programming in Python, we've been working with attributes in relation to classes quite a bit. But for the most part everything that we've done has been related to instance attributes.
One of the fundamental tenants of object-oriented programming in any language is the concept of inheritance. At a high level inheritance is the ability to create specialized versions of classes.
In the last guide, we walked through the concept of inheritance in python. Inheritance by itself is a helpful tool but usually you're going to find inheritance is coupled with the concept called polymorphism and that is what we're going to walk through in this guide.
In the last guide, we walk through how we could leverage polymorphism in a python program to generate HTML. And that is going to be a common way that you implement inheritance and polymorphism.
devCamp does not support ancient browsers.
Install a modern version for best experience.