Check out a free preview of the full Practical Guide to Python course
The "Inheritance" Lesson is part of the full, Practical Guide to Python course featured in this preview video. Here's what you'd learn in this lesson:
Nina shares a brief inheritance example. If a subclass is defined in the same file as its superclass, the class definition should be below the superclass's definition.
Transcript from the "Inheritance" Lesson
[00:00:00]
>> Python does have inheritance and it also has multiple inheritance. I'm not going to jump into a lot of these topics, but I do want to point out a few important things about inheritance. When one class inherits from another, you will put the class that is being inherited from in parentheses after the definition of the class itself.
[00:00:25]
When you are calling Dunder in it on that subclass, if you then want to run all of the code from the superclass, you need to explicitly call super. And then the method that you would call ,in this case we know that we wanna call Dunder in it along with all of the arguments.
[00:00:50]
And this is syntax that you are very likely to run into. So it's important to keep track of. There is a lot more content here in the course about overriding variables in subclasses that I recommend you go back to and read later.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops