Python Practice › OOP Programs › Program 25

Rectangle area class

EasyOOP Programs · 25 of 48

Write a Python class to calculate the area of a rectangle.

Advertisement
Output
40

Approach

  1. Store length and width; return their product.

Solution

Python
class Rectangle:    def __init__(self, length, width):        self.length = length        self.width = width     def area(self):        return self.length * self.width print(Rectangle(8, 5).area())
Output
40
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More oop programs

← All 48 OOP Programs