× Lesson 1 Lesson 2 Lesson 3 Lesson 4 Lesson 5 Lesson 6 Lesson 7 Lesson 8 Lesson 9 Lesson 10 Lesson 11 Lesson 12 Lesson 13 Lesson 14 Lesson 15 Lesson 16 Lesson 17 Lesson 18 Lesson 19 Lesson 20 Lesson 21 Lesson 22 Lesson 23 Lesson 24 Lesson 25 Mini Lesson 1 Mini Lesson 2 Mini Lesson 3 Mini Lesson 4 Mini Lesson 5


Lesson 15 - Inheritance

Inheritance is one of the major concepts in classes and modules, and is possibly the most useful one. The easiest way to explain how they function is through an example: Birds are a super class, or the class that will be inherited by other classes, and it has the attributes color of feathers and wing span and the method fly. Two classes inherit the Bird class, which are birds that can fly, and birds that can't fly. The class of birds that can fly inherit all of the attributes and the method, while the flightless bird class only inherit the attributes. Now three more classes are created, pigeons, robins, and penguins. The pigeons and robin classes inherit from the class of birds that can fly, and inherit all of its attributes and methods, while the penguin class inherits the birds that can't fly attributes and methods, if the birds that can't fly class had in methods.

Here is the basic syntax for a super/base class and a subclass of the base class: class Bird(object): def __init__(self, feathers, wingspan): self.feathers = feathers self.wingspan = wingspan def fly(self): print('I believe I can fly') class BirdsThatCanFly(Bird): def __init__(self):