Object Inheritance in Python

Give Feedback

While Python isn’t purely an object-oriented language, it’s flexible enough and powerful enough to allow you to build your applications using the object-oriented paradigm. One of the ways in which Python achieves this is by supporting inheritance, which it does with super().

By the end of this course, you’ll be able to:

  • Compose a class
  • Use super() to access parent methods
  • Understand single and multiple inheritance

In this lesson, you’ll cover how to use super() to access a parent class’s constructor:

class Rectangle:
    def __init__(self, length, width):
        self.length = length
        self.width = width

    def area(self):
        return self.length * self.width

    def perimeter(self):
        return 2 * self.length + 2 * self.width

class Square(Rectangle):
    def __init__(self, length):
        super().__init__(length, length)

Download

Course Slides (PDF)

896.4 KB

Comments & Discussion

Become a Member to join the conversation.