1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Object-Oriented Programming in Python

Connected

Exercise

Overloading ==

Overloading allows for the functionality of built-in operators be customized using magic methods. In this example, you'll overload the == comparison operator for a Computer class, using the serial number for each device. Have at it!

Instructions

100 XP
  • Define a magic method to overload the == operator used to compare two objects.
  • Use the serial_number attribute to determine if two objects of the Computer class are equal.
  • Create two objects of type Computer with the same serial_number and validate that these objects are equal.