From the course: Python for JavaScript Developers
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Understanding inheritance and mixins - Python Tutorial
From the course: Python for JavaScript Developers
Understanding inheritance and mixins
- [Instructor] So, as we mentioned before, in Python objects can inherit from more than one object. And this allows us to use mix-ins in order to prevent code repetition. Let's see what I mean. So here we have basically a few mix-in classes that we're going to mix and match to create different classes. So on line three, you'll see that I have the veggie mix-in, and all that class has is an attribute called veggies that is a list of vegetables, right? Then we have the soup mix-in which determines the temperature of soup and the percentage of water, right, we're going to say it has 50% added water to it. And then the cook time of three seconds this time, right? And then we have a salad mix-in. And the salad mix-in has a different cooler temperature, right? It has no added water and you don't need to cook this type of salad, right? So let's scroll a little further down. And finally, we have a food mix-in on line 19 and…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.