Daily Python Projects

Daily Python Projects

Share this post

Daily Python Projects
Daily Python Projects
Create magic methods for Rectangle class (OOP)

Create magic methods for Rectangle class (OOP)

Level: Real-World

May 17, 2024
∙ Paid
2

Share this post

Daily Python Projects
Daily Python Projects
Create magic methods for Rectangle class (OOP)
Share

Project Brief

Yesterday, we coded a Rectangle class that had a width and a height attribute. The class also had an area(), perimeter(), and an is_square() method.

Your task for today is to add two magic methods to that class __str__ and __eq__. The __str__ method should return a string representation of the Rectangle and __eq__ should enable comparing two different rectangle instances returning True or False based on whether the rectangles are similar or not (i.e., have the same width and height).

Expected Output

This post is for paid subscribers

Already a paid subscriber? Sign in
© 2025 Ardit Sulce
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share