From the course: Python Object-Oriented Programming

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Using multiple inheritance

Using multiple inheritance

- [Instructor] Unlike some other popular programming languages, Python lets you define classes that can inherit more than one base class. This is called multiple inheritance and while it can be a useful tool, it can also cause a lot of problems if you don't use it carefully. So let's open up the multiple_start example file and we'll see how to use it the right way. Here in my code I have two classes, A and B, each of which define a property. So prop1 is in class A and prop2 is in class B. And then I have a third class named C which lists both A and B as classes that it inherits from, separated by a comma and this is how you inherit from more than one class. So let's go ahead and add a method to class C to print out the properties. We'll call it showprops. And we'll print out self.prop1 and self.prop2. And then let's call that method after the C object is created. And remember, prop1 and prop2 are going to be…

Contents