From the course: Python Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Inheritance

Inheritance

- My child, one day, all of this will be yours. Your inheritance. (ethereal music) So you see, in computer science and in Python, a class can extend another class. The original class is called the parent class, and the class extending it is the child class. And the child class inherits all of the parent classes' methods and attributes. But this inheritance happens automatically when the child class is created. Let's go to the code. - Yeah. - [Instructor] Here, we have the dog class that we used previously, and say we want to use this to make a chihuahua class, which is a type of small dog. Here's how we can do that. Class Chihuahua dog. And let's just add pass for now. We use these parentheses after the class name to indicate that this class is extending the parent dog class. And for now, let's just not add anything else. Just write pass to get this class in place. So we can use this to create a new Chihuahua, and…

Contents