Python Practice › OOP Programs › Program 25
Rectangle area class
Write a Python class to calculate the area of a rectangle.
Output
40
Approach
- Store length and width; return their product.
Solution
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
Learn the concept
New to this topic? Read the lesson, then come back.