Module (3%)
Section (18%)

Python allows us to employ operators when applied to our objects, so we can use core operators on our objects.

Let's imagine the following situation:

  • you've created a class that represents a person;
  • each instance of the class owns a set of attributes describing a person: age, salary, weight, etc.

What does it mean to add two objects of the Person class? Well, it depends on the domain of your application.

If you’re developing an application for an elevator, then you should remember that every elevator has safety limits regarding the total weight it can lift.

tree


In this case, the '+' operator, when applied to two objects, should mean: add the weight attribute values and return the corresponding result.

If the total sum of the weights of the Person class objects does not exceed the safety limit, your elevator should allow them to be lifted.

inside elevator