In Python, inheritance works like this:

class DerivedClass(BaseClass): # code goes here

where DerivedClass is the new class you’re making and BaseClass is the class from which that new class inherits.



On lines 1-4, we’ve created a class named Shape.

  • Create your own class, Triangle, that inherits from Shape, like this:
    class Triangle(Shape): # code goes here
  • Inside the Triangle class, write an __init__() function that takes four arguments: self, side1, side2, and side3.
  • Inside the __init__() function, set self.side1 = side1, self.side2 = side2, and self.side3 = side3.

Click “Stuck? Get a hint!” for an example.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?