In this lesson, 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 lesson, 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.
Peter T on March 22, 2019
In the above text, please change exampole to example.