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

Connected

Exercise

Overloading the == operator

Python's built-in operators are handy, especially when comparing instances of a class. When building classes, magic methods can be used to change the functionality of these operators. Here, you'll overload the == operator to determine if two instances of a Computer are equal.

Instructions

100 XP
  • Define a magic method to overload the == operator.
  • Compare the device_id attributes of self and other in the magic method to determine if the two instances are equal.
  • Check if pre_upgrade_computer and post_upgrade_computer are equal, and print the result.