Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Introduction to OOP Inheritance

Give Feedback

In this video, you’ll learn how inheritance is used to write maintainable Python code that avoids redundancy.

Inheritance allows one class to subclass another. If we want to make the Baby class a child class of the Person class, we can define Baby like this:

class Baby(Person):
    # Baby code here

By default, any Baby object we create will inherit its attributes and methods from its parent. This means it will have the same attributes and members that the parent class defined.

In the video, you’ll see how you can override a method so that the Baby class can contain a different implementation for that method. You’ll also learn how to extend the functionality of the Baby class by defining new methods, which will be exclusive to only Baby objects.

The isinstance() function is used to determine if an object is of a specific type. It takes 2 arguments: the object to be checked, and a type to check against. It supports inheritance, so in the example of our Baby and Person objects, isinstance(baby, Person) will return True because our Baby class is the child class of Person, and so we can say our baby object is a Person too.

Comments & Discussion

Peter T on March 22, 2019

In the above text, please change exampole to example.

John T on March 28, 2019

Lovely tutorial. very clear and concise. but dawg , its 2019. use f strings :)

Eriberto on April 27, 2019

f string +1 lol why can’t we streamline the use of awesome formatting method python 2 is dead soon 😀

justpeter25x on Nov. 15, 2019

Thank you.The course is very good . If you provide the video transcript with the course it will be very helpful.It will save our time

Austin Cepalia RP Team on Nov. 16, 2019

@justpeter25x That’s a good idea, but unfortunately that’s beyond my control

Dan Bader RP Team on Nov. 16, 2019

Thanks for your comment @justpeter25x. I’m planning to bring full transcripts and subtitles to all courses on Real Python in the future. It’s a huge project but I agree that it will be very useful. Stay tuned :)

L3ARaX on Dec. 25, 2019

Can’t wait for an English subtitles for non native speakers… like me ^_^.

Become a Member to join the conversation.